From e67951b1b42b5a707dc6959db0810e0f139a9dbb Mon Sep 17 00:00:00 2001 From: ricston-git Date: Fri, 20 Apr 2018 10:25:33 +0200 Subject: [PATCH] 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 --- README.md | 6 ++++++ defaults/main.yml | 6 ++++++ tasks/amplify.yml | 45 +++++++++++++++++++++++++++++++++++++++++++++ tasks/main.yml | 4 ++++ 4 files changed, 61 insertions(+) create mode 100644 tasks/amplify.yml diff --git a/README.md b/README.md index 1131cfd..043cb12 100644 --- a/README.md +++ b/README.md @@ -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 ------- @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml index 3cced48..38dbb88 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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" \ No newline at end of file diff --git a/tasks/amplify.yml b/tasks/amplify.yml new file mode 100644 index 0000000..874696c --- /dev/null +++ b/tasks/amplify.yml @@ -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] \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 97bf0d8..0cb55b8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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"