From a55a50d570d00b797488a3ccc2674cf5a4ee6809 Mon Sep 17 00:00:00 2001 From: Alessandro Fael Garcia Date: Wed, 12 Sep 2018 14:03:20 -0700 Subject: [PATCH] Refactor NGINX Amplify agent installation --- README.md | 2 +- defaults/main.yml | 2 +- handlers/main.yml | 15 ++++++++++----- tasks/amplify/install-amplify.yml | 28 +++++++++++++++++++++------- tasks/amplify/setup-debian.yml | 5 +++++ tasks/amplify/setup-redhat.yml | 8 ++++++++ tasks/main.yml | 2 +- 7 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 tasks/amplify/setup-debian.yml create mode 100644 tasks/amplify/setup-redhat.yml diff --git a/README.md b/README.md index c5091f2..923d2b4 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ modules: # Requires access to either the NGINX stub status or the NGINX Plus REST API. # Default is null. amplify_enable: false -amplify_key: null +amplify_api_key: null # Install NGINX Controller. # Use your NGINX Controller API key and NGINX Controller API endpoint. diff --git a/defaults/main.yml b/defaults/main.yml index 6c5ae96..c2c6ef5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -58,7 +58,7 @@ modules: # Requires access to either the NGINX stub status or the NGINX Plus REST API. # Default is null. amplify_enable: false -amplify_key: null +amplify_api_key: null # Install NGINX Controller. # Use your NGINX Controller API key and NGINX Controller API endpoint. diff --git a/handlers/main.yml b/handlers/main.yml index ae32703..15903fa 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -10,6 +10,16 @@ name: nginx state: reloaded +- name: "(Handler: All OSs) Start NGINX Amplify Agent" + service: + name: amplify-agent + state: started + +- name: "(Handler: All OSs) Start NGINX Controller Agent" + service: + name: controller-agent + state: started + - name: "(Handler: Debian/Ubuntu/CentOS/RedHat) Start NGINX Unit" service: name: unit @@ -21,8 +31,3 @@ name: unitd state: started enabled: yes - -- name: "(Handler: All OSs) Start NGINX Controller Agent" - service: - name: controller-agent - state: started diff --git a/tasks/amplify/install-amplify.yml b/tasks/amplify/install-amplify.yml index 95013d6..16c0a30 100644 --- a/tasks/amplify/install-amplify.yml +++ b/tasks/amplify/install-amplify.yml @@ -1,10 +1,24 @@ --- -- import_tasks: ../conf/setup-status.yml +- import_tasks: setup-debian.yml + when: ansible_os_family == "Debian" -- name: "(Install: All NGINX) Download NGINX Amplify Script" - get_url: - url: https://github.com/nginxinc/nginx-amplify-agent/raw/master/packages/install.sh - dest: /tmp/install.sh +- import_tasks: setup-redhat.yml + when: ansible_os_family == "RedHat" -- name: "(Install: All NGINX) Install NGINX Amplify" - shell: API_KEY='{{ amplify_key }}' sh /tmp/install.sh -y +- name: "(Install: All OSs) Install NGINX Amplify Agent" + package: + name: nginx-amplify-agent + state: present + +- name: "(Setup: All OSs) Copy NGINX Configurator Agent Configuration Template" + copy: + remote_src: yes + src: /etc/amplify-agent/agent.configurator.conf.default + dest: /etc/amplify-agent/agent.configurator.conf + +- name: "(Setup: All OSs) Configure NGINX Amplify Agent API Key" + lineinfile: + dest: /etc/amplify-agent/agent.conf + regexp: api_key =.* + line: "api_key = {{ amplify_api_key }}" + notify: "(Handler: All OSs) Start NGINX Amplify Agent" diff --git a/tasks/amplify/setup-debian.yml b/tasks/amplify/setup-debian.yml new file mode 100644 index 0000000..406d6d2 --- /dev/null +++ b/tasks/amplify/setup-debian.yml @@ -0,0 +1,5 @@ +--- +- name: "(Install: Debian/Ubuntu) Add NGINX Amplify Agent Repository" + apt_repository: + filename: nginx-amplify + repo: deb http://packages.amplify.nginx.com/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} amplify-agent diff --git a/tasks/amplify/setup-redhat.yml b/tasks/amplify/setup-redhat.yml new file mode 100644 index 0000000..154da5e --- /dev/null +++ b/tasks/amplify/setup-redhat.yml @@ -0,0 +1,8 @@ +--- +- name: "(Install: CentOS/RedHat/Amazon Linux) Add NGINX Amplify Agent Repository" + yum_repository: + name: nginx-amplify + baseurl: http://packages.amplify.nginx.com/{{ (ansible_distribution == "Amazon") | ternary('amzn/', 'centos/') }}/$releasever/$basearch/ + description: NGINX Amplify Agent + enabled: yes + gpgcheck: yes diff --git a/tasks/main.yml b/tasks/main.yml index 8941d0b..925589e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -34,7 +34,7 @@ when: nginx_enable - import_tasks: amplify/install-amplify.yml - when: amplify_enable and amplify_key is defined and amplify_key + when: amplify_enable and amplify_api_key is defined and amplify_api_key - import_tasks: controller/install-controller.yml when: controller_enable and controller_api_key is defined and controller_api_key and controller_api_endpoint is defined and controller_api_endpoint