Skip to content

Commit f54b7d2

Browse files
authored
Add new method to install the NGINX Controller agent (#205)
1 parent 3b6c744 commit f54b7d2

File tree

8 files changed

+126
-63
lines changed

8 files changed

+126
-63
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a
379379
nginx_type: plus
380380
```
381381

382-
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost to install NGINX Plus and the NGINX Controller agent.
382+
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost to install NGINX Plus and the NGINX Controller agent. Commented out
383+
are sample variables to install the NGINX Controller agent from your NGINX Controller instance instead of the NGINX repository.
383384

384385
```yaml
385386
- hosts: localhost
@@ -392,8 +393,18 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a
392393
nginx_rest_api_port: 80
393394
nginx_rest_api_write: true
394395
nginx_controller_enable: true
396+
nginx_controller_source: repository
395397
nginx_controller_api_key: <API_KEY_HERE>
396-
nginx_controller_api_endpoint: https://<FQDN>/1.4
398+
nginx_controller_endpoint: <FQDN> # e.g. controller.nginx.com
399+
# nginx_type: plus
400+
# nginx_rest_api_enable: true
401+
# nginx_rest_api_port: 80
402+
# nginx_rest_api_write: true
403+
# nginx_controller_enable: true
404+
# nginx_controller_source: instance
405+
# nginx_controller_endpoint: controller.nginx.com
406+
# nginx_controller_user_email: [email protected]
407+
# nginx_controller_password: password
397408
```
398409

399410
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost to install NGINX Unit and the PHP/Perl NGINX Unit language modules.

defaults/main/controller.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
---
2-
# Install NGINX Controller.
3-
# Use your NGINX Controller API key and NGINX Controller API endpoint.
2+
# Install NGINX Controller Agent.
43
# Requires NGINX Plus and write access to the NGINX Plus REST API.
5-
# Default is null.
64
nginx_controller_enable: false
5+
6+
# Set the source from where to pull the NGINX Controller Agent.
7+
# Options are 'instance', to pull the NGINX Controller Agent install script
8+
# from your NGINX Controller instance, or 'repository', to pull the NGINX
9+
# Controller Agent from the NGINX repository.
10+
# Default is instance.
11+
nginx_controller_source: instance
12+
13+
# Set your NGINX Controller Endpoint. Required for both types of NGINX Controller
14+
# installation.
15+
nginx_controller_endpoint: null
16+
17+
# Set your NGINX Controller API key.
18+
# Required when 'nginx_controller_source' is set to 'repository'.
19+
# Default is null.
720
nginx_controller_api_key: null
8-
nginx_controller_api_endpoint: null
21+
22+
# Set your NGINX Controller Admin Email and Password.
23+
# Required when 'nginx_controller_source' is set to 'instance'.
24+
nginx_controller_user_email: null
25+
nginx_controller_password: null
Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,15 @@
11
---
2-
- import_tasks: setup-debian.yml
3-
when: ansible_os_family == "Debian"
4-
5-
- import_tasks: setup-redhat.yml
6-
when: ansible_os_family == "RedHat"
7-
8-
- name: "(Install: All OSs) Install NGINX Controller Agent"
9-
package:
10-
name: nginx-controller-agent
11-
state: present
12-
13-
- name: "(Setup: All OSs) Copy NGINX Controller Agent Configuration Template"
14-
copy:
15-
remote_src: yes
16-
src: /etc/controller-agent/agent.controller.conf.default
17-
dest: /etc/controller-agent/agent.conf
18-
19-
- name: "(Setup: All OSs) Copy NGINX Configurator Agent Configuration Template"
20-
copy:
21-
remote_src: yes
22-
src: /etc/controller-agent/agent.configurator.conf.default
23-
dest: /etc/controller-agent/agent.configurator.conf
24-
25-
- name: "(Setup: All OSs) Configure NGINX Controller Agent API Key"
26-
lineinfile:
27-
dest: /etc/controller-agent/agent.conf
28-
regexp: api_key =.*
29-
line: "api_key = {{ nginx_controller_api_key }}"
30-
31-
- name: "(Setup: All OSs) Configure NGINX Controller Agent API URL"
32-
lineinfile:
33-
dest: /etc/controller-agent/agent.conf
34-
regexp: api_url =.*
35-
line: "api_url = {{ nginx_controller_api_endpoint }}"
36-
37-
- name: "(Setup: All OSs) Configure NGINX Controller Agent API Hostname"
38-
lineinfile:
39-
dest: /etc/controller-agent/agent.conf
40-
regexp: hostname =.*
41-
line: "hostname = {{ ansible_hostname }}"
42-
notify: "(Handler: All OSs) Start NGINX Controller Agent"
2+
- import_tasks: setup-controller-instance.yml
3+
when:
4+
- nginx_controller_source == "instance"
5+
- nginx_controller_user_email is defined
6+
- nginx_controller_user_email | length > 0
7+
- nginx_controller_password is defined
8+
- nginx_controller_password | length > 0
9+
10+
11+
- import_tasks: setup-controller-repository.yml
12+
when:
13+
- nginx_controller_source == "repository"
14+
- nginx_controller_api_key is defined
15+
- nginx_controller_api_key | length > 0
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
- name: "(Install: All OSs) Fetch NGINX Controller API Key"
3+
uri:
4+
url: "https://{{ nginx_controller_endpoint }}/sapi/auth/login/"
5+
method: "POST"
6+
body:
7+
email: "{{ nginx_controller_user_email }}"
8+
password: "{{ nginx_controller_password }}"
9+
body_format: json
10+
return_content: yes
11+
status_code: 200
12+
validate_certs: false
13+
register: controller_return
14+
15+
- name: "(Install: All OSs) Download the NGINX Controller Agent Installer Script"
16+
get_url:
17+
url: "https://{{ nginx_controller_endpoint }}:8443/1.4/install/controller/"
18+
dest: /tmp/install.sh
19+
validate_certs: no
20+
force: yes
21+
22+
- name: "(Install: All OSs) Run the NGINX Controller Agent Installer Script"
23+
command: "sh ./install.sh -y"
24+
args:
25+
chdir: /tmp
26+
creates: /var/log/nginx-controller/agent.log
27+
environment:
28+
API_KEY: "{{ controller_return.json.api_key }}"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
- name: "(Install: Debian/Ubuntu) Add NGINX Controller Agent Repository"
3+
apt_repository:
4+
filename: nginx-controller
5+
repo: deb https://packages.nginx.org/controller/{{ ansible_distribution | lower }}/ {{ ansible_distribution_release | lower }} controller
6+
7+
- name: "(Install: CentOS/RedHat) Add NGINX Controller Agent Repository"
8+
yum_repository:
9+
name: nginx-controller
10+
baseurl: https://packages.nginx.org/controller/centos/$releasever/$basearch/
11+
description: NGINX Controller Agent
12+
gpgcheck: yes
13+
14+
- name: "(Install: All OSs) Install NGINX Controller Agent"
15+
package:
16+
name: nginx-controller-agent
17+
state: present
18+
19+
- name: "(Setup: All OSs) Copy NGINX Controller Agent Configuration Template"
20+
copy:
21+
remote_src: yes
22+
src: /etc/controller-agent/agent.controller.conf.default
23+
dest: /etc/controller-agent/agent.conf
24+
25+
- name: "(Setup: All OSs) Copy NGINX Configurator Agent Configuration Template"
26+
copy:
27+
remote_src: yes
28+
src: /etc/controller-agent/agent.configurator.conf.default
29+
dest: /etc/controller-agent/agent.configurator.conf
30+
31+
- name: "(Setup: All OSs) Configure NGINX Controller Agent API Key"
32+
lineinfile:
33+
dest: /etc/controller-agent/agent.conf
34+
regexp: api_key =.*
35+
line: "api_key = {{ nginx_controller_api_key }}"
36+
37+
- name: "(Setup: All OSs) Configure NGINX Controller Agent API URL"
38+
lineinfile:
39+
dest: /etc/controller-agent/agent.conf
40+
regexp: api_url =.*
41+
line: "api_url = https://{{ nginx_controller_endpoint }}/1.4"
42+
43+
- name: "(Setup: All OSs) Configure NGINX Controller Agent API Hostname"
44+
lineinfile:
45+
dest: /etc/controller-agent/agent.conf
46+
regexp: hostname =.*
47+
line: "hostname = {{ ansible_hostname }}"
48+
notify: "(Handler: All OSs) Start NGINX Controller Agent"

tasks/controller/setup-debian.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

tasks/controller/setup-redhat.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

tasks/main.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@
8585
- import_tasks: controller/install-controller.yml
8686
when:
8787
- nginx_controller_enable | bool
88-
- nginx_controller_api_key is defined
89-
- nginx_controller_api_key | length > 0
90-
- nginx_controller_api_endpoint is defined
91-
- nginx_controller_api_endpoint | length > 0
88+
- nginx_controller_endpoint is defined
89+
- nginx_controller_endpoint | length > 0
9290
tags: nginx_install_controller
9391

9492
- import_tasks: unit/install-unit.yml

0 commit comments

Comments
 (0)