Skip to content

Commit 65ab26a

Browse files
authored
Merge pull request #59 from nginxinc/(feature)/install-controller
Install NGINX Controller agent
2 parents a8db981 + 809b9e3 commit 65ab26a

File tree

8 files changed

+195
-47
lines changed

8 files changed

+195
-47
lines changed

README.md

Lines changed: 96 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Use `ansible-galaxy install nginxinc.nginx` to install the role on your system.
1717

1818
It supports all platforms supported by [NGINX Open Source](https://nginx.org/en/linux_packages.html#mainline) and [NGINX Plus](https://www.nginx.com/products/technical-specs/):
1919

20-
**NGINX Open Source:**
20+
**NGINX Open Source**
2121

2222
```yaml
2323
CentOS:
@@ -47,7 +47,7 @@ FreeBSD:
4747
- 11
4848
```
4949
50-
**NGINX Plus:**
50+
**NGINX Plus**
5151
5252
```yaml
5353
CentOS:
@@ -84,7 +84,52 @@ FreeBSD:
8484
- 11
8585
```
8686
87-
**NGINX Unit:**
87+
**NGINX Amplify**
88+
89+
```yaml
90+
CentOS:
91+
versions:
92+
- 6
93+
- 7
94+
RedHat:
95+
versions:
96+
- 6
97+
- 7
98+
Debian:
99+
versions:
100+
- jessie
101+
- stretch
102+
Ubuntu:
103+
versions:
104+
- trusty
105+
- xenial
106+
- artful
107+
- bionic
108+
Amazon Linux:
109+
versions:
110+
- 2017.09
111+
```
112+
113+
**NGINX Controller**
114+
115+
```yaml
116+
CentOS:
117+
versions:
118+
- 7
119+
RedHat:
120+
versions:
121+
- 7
122+
Debian:
123+
versions:
124+
- jessie
125+
- stretch
126+
Ubuntu:
127+
versions:
128+
- xenial
129+
- artful
130+
```
131+
132+
**NGINX Unit**
88133
89134
```yaml
90135
CentOS:
@@ -154,6 +199,16 @@ nginx_repository:
154199
# Default is mainline.
155200
branch: mainline
156201

202+
# Location of your NGINX Plus license in your local machine.
203+
# Default is the files folder within the NGINX Ansible role.
204+
license:
205+
certificate: license/nginx-repo.crt
206+
key: license/nginx-repo.key
207+
208+
# Delete NGINX Plus license after installation for security purposes.
209+
# Default is true.
210+
delete_license: true
211+
157212
# Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules.
158213
# Default is false.
159214
modules:
@@ -167,31 +222,37 @@ modules:
167222

168223
# Install NGINX Amplify.
169224
# Use your NGINX Amplify API key.
225+
# Requires access to either the NGINX stub status or the NGINX Plus REST API.
170226
# Default is null.
171227
amplify_enable: false
172228
amplify_key: null
173229

230+
# Install NGINX Controller.
231+
# Use your NGINX Controller API key and NGINX Controller API endpoint.
232+
# Requires NGINX Plus and write access to the NGINX Plus REST API.
233+
# Default is null.
234+
controller_enable: false
235+
controller_api_key: null
236+
controller_api_endpoint: null
237+
238+
# Install NGINX Unit and NGINX Unit modules.
239+
# Use a list of supported NGINX Unit modules.
240+
# Default is false.
241+
unit_enable: false
242+
unit_modules: null
243+
174244
# Enable NGINX status data.
175245
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
176246
# Default is false.
177247
status_enable: false
178248

179249
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
250+
# Requires NGINX Plus.
180251
# Default is false.
181252
rest_api_enable: false
182253
rest_api_write: false
183254
rest_api_dashboard: false
184255

185-
# Location of your NGINX Plus license in your local machine.
186-
# Default is the files folder within the NGINX Ansible role.
187-
license:
188-
certificate: license/nginx-repo.crt
189-
key: license/nginx-repo.key
190-
191-
# Delete NGINX Plus license after installation for security purposes.
192-
# Default is true.
193-
delete_license: true
194-
195256
# Enable uploading NGINX configuration files to your system.
196257
# Default for uploading files is false.
197258
# Default location of files is the files folder within the NGINX Ansible role.
@@ -215,12 +276,6 @@ http_template_listen: 80
215276
http_template_server_name: localhost
216277
stream_template_enable: false
217278
stream_template_listen: 12345
218-
219-
# Install NGINX Unit and NGINX Unit modules.
220-
# Use a list of supported NGINX Unit modules.
221-
# Default is false.
222-
unit_enable: false
223-
unit_modules: null
224279
```
225280
226281
Dependencies
@@ -241,6 +296,16 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a
241296
- role: nginxinc.nginx
242297
```
243298
299+
This is a sample playbook file for deploying the Ansible Galaxy NGINX role to a dynamic inventory containing the `nginx` tag.
300+
301+
```yaml
302+
---
303+
- hosts: tag_nginx
304+
remote_user: root
305+
roles:
306+
- role: nginxinc.nginx
307+
```
308+
244309
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost and installing NGINX Plus.
245310

246311
```yaml
@@ -253,19 +318,25 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a
253318
type: plus
254319
```
255320

256-
This is a sample playbook file for deploying the Ansible Galaxy NGINX role to a dynamic inventory containing the `nginx` tag.
321+
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.
257322

258-
```yml
259-
---
260-
- hosts: tag_nginx
261-
remote_user: root
323+
```yaml
324+
- hosts: localhost
325+
become: true
262326
roles:
263327
- role: nginxinc.nginx
328+
vars:
329+
type: plus
330+
rest_api_enable: true
331+
rest_api_write: true
332+
controller_enable: true
333+
controller_api_key: <API_KEY_HERE>
334+
controller_api_endpoint: https://<FQDN>/1.4
264335
```
265336

266337
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.
267338

268-
```yml
339+
```yaml
269340
---
270341
- hosts: localhost
271342
become: true

defaults/main.yml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ nginx_repository:
3232
# Default is mainline.
3333
branch: mainline
3434

35+
# Location of your NGINX Plus license in your local machine.
36+
# Default is the files folder within the NGINX Ansible role.
37+
license:
38+
certificate: license/nginx-repo.crt
39+
key: license/nginx-repo.key
40+
41+
# Delete NGINX Plus license after installation for security purposes.
42+
# Default is true.
43+
delete_license: true
44+
3545
# Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules.
3646
# Default is false.
3747
modules:
@@ -45,31 +55,37 @@ modules:
4555

4656
# Install NGINX Amplify.
4757
# Use your NGINX Amplify API key.
58+
# Requires access to either the NGINX stub status or the NGINX Plus REST API.
4859
# Default is null.
4960
amplify_enable: false
5061
amplify_key: null
5162

63+
# Install NGINX Controller.
64+
# Use your NGINX Controller API key and NGINX Controller API endpoint.
65+
# Requires NGINX Plus and write access to the NGINX Plus REST API.
66+
# Default is null.
67+
controller_enable: false
68+
controller_api_key: null
69+
controller_api_endpoint: null
70+
71+
# Install NGINX Unit and NGINX Unit modules.
72+
# Use a list of supported NGINX Unit modules.
73+
# Default is false.
74+
unit_enable: false
75+
unit_modules: null
76+
5277
# Enable NGINX status data.
5378
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
5479
# Default is false.
5580
status_enable: false
5681

5782
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
83+
# Requires NGINX Plus.
5884
# Default is false.
5985
rest_api_enable: false
6086
rest_api_write: false
6187
rest_api_dashboard: false
6288

63-
# Location of your NGINX Plus license in your local machine.
64-
# Default is the files folder within the NGINX Ansible role.
65-
license:
66-
certificate: license/nginx-repo.crt
67-
key: license/nginx-repo.key
68-
69-
# Delete NGINX Plus license after installation for security purposes.
70-
# Default is true.
71-
delete_license: true
72-
7389
# Enable uploading NGINX configuration files to your system.
7490
# Default for uploading files is false.
7591
# Default location of files is the files folder within the NGINX Ansible role.
@@ -93,9 +109,3 @@ http_template_listen: 80
93109
http_template_server_name: localhost
94110
stream_template_enable: false
95111
stream_template_listen: 12345
96-
97-
# Install NGINX Unit and NGINX Unit modules.
98-
# Use a list of supported NGINX Unit modules.
99-
# Default is false.
100-
unit_enable: false
101-
unit_modules: null

handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@
2121
name: unitd
2222
state: started
2323
enabled: yes
24+
25+
- name: "(Handler: All OSs) Start NGINX Controller Agent"
26+
service:
27+
name: controller-agent
28+
state: started

meta/main.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ galaxy_info:
3434

3535
galaxy_tags:
3636
- nginx
37-
- amplify
37+
- nginx-oss
3838
- oss
39+
- nginx-plus
3940
- plus
41+
- nginx-amplify
42+
- amplify
43+
- nginx-controller
44+
- controller
45+
- nginx-unit
46+
- unit
4047
- web
4148
- server
42-
- unit
4349
- development
44-
- web
4550

4651
dependencies: []
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
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 = {{ 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 = {{ 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"

tasks/controller/setup-debian.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: "(Install: Debian/Ubuntu) Add NGINX Controller Agent Repository"
3+
apt_repository:
4+
filename: nginx-controller
5+
repo: deb http://packages.nginx.org/controller/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release|lower }} controller

tasks/controller/setup-redhat.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: "(Install: CentOS/RedHat) Add NGINX Controller Agent Repository"
3+
yum_repository:
4+
name: nginx-controller
5+
baseurl: http://packages.nginx.org/controller/centos/$releasever/$basearch/
6+
description: NGINX Controller Agent
7+
gpgcheck: yes

tasks/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
- import_tasks: conf/setup-rest-api.yml
3232
when: rest_api_enable and type == "plus"
3333

34-
- import_tasks: amplify/install-amplify.yml
35-
when: amplify_enable and amplify_key is defined and amplify_key
36-
3734
when: nginx_enable
3835

36+
- import_tasks: amplify/install-amplify.yml
37+
when: amplify_enable and amplify_key is defined and amplify_key
38+
39+
- import_tasks: controller/install-controller.yml
40+
when: controller_enable and controller_api_key is defined and controller_api_key and controller_api_endpoint is defined and controller_api_endpoint
41+
3942
- import_tasks: unit/install-unit.yml
4043
when: unit_enable

0 commit comments

Comments
 (0)