Skip to content

Refactor NGINX Amplify agent installation #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 10 additions & 5 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,8 +31,3 @@
name: unitd
state: started
enabled: yes

- name: "(Handler: All OSs) Start NGINX Controller Agent"
service:
name: controller-agent
state: started
28 changes: 21 additions & 7 deletions tasks/amplify/install-amplify.yml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions tasks/amplify/setup-debian.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tasks/amplify/setup-redhat.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down