Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
Support Nginx Amplify (#218)
Browse files Browse the repository at this point in the history
* Support nginx amplify.

* Updated readme.

* Added missing Ansible tags.

* Fixed comments related to PR review.

* Limited installation of Nginx Amplify to the list of supported operating systems, as stated by Nginx's documentation.

* Add nginx tag
  • Loading branch information
ricston-git authored and jdauphant committed Apr 20, 2018
1 parent bafaf81 commit e67951b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Requirements
This role requires Ansible 2.4 or higher and platform requirements are listed
in the metadata file. (Some older version of the role support Ansible 1.4)
For FreeBSD a working pkgng setup is required (see: https://www.freebsd.org/doc/handbook/pkgng-intro.html )
Installation of Nginx Amplify agent is only supported on CentOS, RedHat, Amazon, Debian and Ubuntu distributions.

Install
-------
Expand Down Expand Up @@ -97,6 +98,11 @@ nginx_auth_basic_files:

# Enable Real IP for CloudFlare requests
nginx_set_real_ip_from_cloudflare: True

# Enable Nginx Amplify
nginx_amplify: true
nginx_amplify_api_key: "your_api_key_goes_here"
nginx_amplify_update_agent: true
```
Examples
Expand Down
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ nginx_start_at_boot: true
nginx_set_real_ip_from_cloudflare: False
nginx_cloudflare_real_ip_header: "CF-Connecting-IP" # See: https://support.cloudflare.com/hc/en-us/articles/200170706-How-do-I-restore-original-visitor-IP-with-Nginx-
nginx_cloudflare_configuration_name: "cloudflare" # Name for the conf file in the conf.d directory

nginx_amplify: false
nginx_amplify_api_key: ""
nginx_amplify_update_agent: false
nginx_amplify_script_url: "https://github.com/nginxinc/nginx-amplify-agent/raw/master/packages/install.sh"
nginx_amplify_script_path: "/tmp/install-amplify-agent.sh"
45 changes: 45 additions & 0 deletions tasks/amplify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- name: Check if Amplify Agent is installed
package:
name: nginx-amplify-agent
state: present
ignore_errors: true
register: amplify_agent_installed
tags: [packages]

- name: Install Amplify Agent if not installed
block:
- name: Download Amplify Agent script
get_url:
url: "{{ nginx_amplify_script_url }}"
dest: "{{ nginx_amplify_script_path }}"

- name: Run Amplify Agent install.sh script
command: "sh /tmp/install-amplify-agent.sh -y"
environment:
API_KEY: "{{ amplify.api_key }}"
become: true
become_user: root
become_method: sudo

- name: Remove installation script
file:
path: "{{ nginx_amplify_script_path }}"
state: absent

when: amplify_agent_installed.failed == true
tags: [configuration, packages]

- name: Update Amplify Agent if already installed and update flag is enabled
package:
name: nginx-amplify-agent
state: latest
when: amplify_agent_installed.failed == false and nginx_amplify_update_agent == true
tags: [packages]

- name: Verify Amplify agent is up and running
service:
name: amplify-agent
state: started
enabled: true
tags: [service]
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
when: nginx_set_real_ip_from_cloudflare == True
tags: [configuration, nginx]

- include_tasks: amplify.yml
when: nginx_amplify == true and (ansible_distribution in ['RedHat', 'CentOS', 'Debian', 'Amazon', 'Ubuntu'])
tags: [amplify, nginx]

- name: Start the nginx service
service: name={{ nginx_service_name }} state={{nginx_start_service | ternary('started', 'stopped')}} enabled={{nginx_start_at_boot}}
when: nginx_installation_type in nginx_installation_types_using_service and nginx_daemon_mode == "on"
Expand Down

0 comments on commit e67951b

Please sign in to comment.