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

Commit e67951b

Browse files
ricston-gitjdauphant
authored andcommitted
Support Nginx Amplify (#218)
* 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
1 parent bafaf81 commit e67951b

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Requirements
1414
This role requires Ansible 2.4 or higher and platform requirements are listed
1515
in the metadata file. (Some older version of the role support Ansible 1.4)
1616
For FreeBSD a working pkgng setup is required (see: https://www.freebsd.org/doc/handbook/pkgng-intro.html )
17+
Installation of Nginx Amplify agent is only supported on CentOS, RedHat, Amazon, Debian and Ubuntu distributions.
1718

1819
Install
1920
-------
@@ -97,6 +98,11 @@ nginx_auth_basic_files:
9798

9899
# Enable Real IP for CloudFlare requests
99100
nginx_set_real_ip_from_cloudflare: True
101+
102+
# Enable Nginx Amplify
103+
nginx_amplify: true
104+
nginx_amplify_api_key: "your_api_key_goes_here"
105+
nginx_amplify_update_agent: true
100106
```
101107
102108
Examples

defaults/main.yml

+6
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,9 @@ nginx_start_at_boot: true
7272
nginx_set_real_ip_from_cloudflare: False
7373
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-
7474
nginx_cloudflare_configuration_name: "cloudflare" # Name for the conf file in the conf.d directory
75+
76+
nginx_amplify: false
77+
nginx_amplify_api_key: ""
78+
nginx_amplify_update_agent: false
79+
nginx_amplify_script_url: "https://github.com/nginxinc/nginx-amplify-agent/raw/master/packages/install.sh"
80+
nginx_amplify_script_path: "/tmp/install-amplify-agent.sh"

tasks/amplify.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
- name: Check if Amplify Agent is installed
3+
package:
4+
name: nginx-amplify-agent
5+
state: present
6+
ignore_errors: true
7+
register: amplify_agent_installed
8+
tags: [packages]
9+
10+
- name: Install Amplify Agent if not installed
11+
block:
12+
- name: Download Amplify Agent script
13+
get_url:
14+
url: "{{ nginx_amplify_script_url }}"
15+
dest: "{{ nginx_amplify_script_path }}"
16+
17+
- name: Run Amplify Agent install.sh script
18+
command: "sh /tmp/install-amplify-agent.sh -y"
19+
environment:
20+
API_KEY: "{{ amplify.api_key }}"
21+
become: true
22+
become_user: root
23+
become_method: sudo
24+
25+
- name: Remove installation script
26+
file:
27+
path: "{{ nginx_amplify_script_path }}"
28+
state: absent
29+
30+
when: amplify_agent_installed.failed == true
31+
tags: [configuration, packages]
32+
33+
- name: Update Amplify Agent if already installed and update flag is enabled
34+
package:
35+
name: nginx-amplify-agent
36+
state: latest
37+
when: amplify_agent_installed.failed == false and nginx_amplify_update_agent == true
38+
tags: [packages]
39+
40+
- name: Verify Amplify agent is up and running
41+
service:
42+
name: amplify-agent
43+
state: started
44+
enabled: true
45+
tags: [service]

tasks/main.yml

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
when: nginx_set_real_ip_from_cloudflare == True
4141
tags: [configuration, nginx]
4242

43+
- include_tasks: amplify.yml
44+
when: nginx_amplify == true and (ansible_distribution in ['RedHat', 'CentOS', 'Debian', 'Amazon', 'Ubuntu'])
45+
tags: [amplify, nginx]
46+
4347
- name: Start the nginx service
4448
service: name={{ nginx_service_name }} state={{nginx_start_service | ternary('started', 'stopped')}} enabled={{nginx_start_at_boot}}
4549
when: nginx_installation_type in nginx_installation_types_using_service and nginx_daemon_mode == "on"

0 commit comments

Comments
 (0)