Skip to content

Commit 02db93d

Browse files
committed
Merge branch 'master' into (feature)/unit
Bring the (feature)/unit branch up to date with the master branch
2 parents 033da66 + ba092d0 commit 02db93d

33 files changed

+472
-148
lines changed

.travis.yml

Lines changed: 89 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,94 @@
11
---
2-
language: python
3-
python: "2.7"
4-
# Use the new container infrastructure
5-
sudo: false
6-
# Install ansible
7-
addons:
8-
apt:
9-
packages:
10-
- python-pip
11-
install:
12-
# Install ansible
13-
- pip install ansible
14-
# Check ansible version
15-
- ansible --version
16-
# Create ansible.cfg with correct roles_path
17-
- printf '[defaults]\nroles_path=../' >ansible.cfg
2+
sudo: required
3+
services:
4+
- docker
5+
env:
6+
- distribution: centos
7+
version: 6
8+
playbook: basic
9+
- distribution: centos
10+
version: 6
11+
playbook: push
12+
- distribution: centos
13+
version: 6
14+
playbook: stable
15+
- distribution: centos
16+
version: 6
17+
playbook: template
18+
- distribution: centos
19+
version: 7
20+
playbook: basic
21+
- distribution: centos
22+
version: 7
23+
playbook: template
24+
- distribution: centos
25+
version: 7
26+
playbook: stable
27+
- distribution: centos
28+
version: 7
29+
playbook: push
30+
- distribution: debian
31+
version: jessie
32+
playbook: basic
33+
- distribution: debian
34+
version: jessie
35+
playbook: template
36+
- distribution: debian
37+
version: jessie
38+
playbook: stable
39+
- distribution: debian
40+
version: jessie
41+
playbook: push
42+
- distribution: debian
43+
version: stretch
44+
playbook: basic
45+
- distribution: debian
46+
version: stretch
47+
playbook: template
48+
- distribution: debian
49+
version: stretch
50+
playbook: stable
51+
- distribution: debian
52+
version: stretch
53+
playbook: push
54+
- distribution: ubuntu
55+
version: trusty
56+
playbook: basic
57+
- distribution: ubuntu
58+
version: trusty
59+
playbook: template
60+
- distribution: ubuntu
61+
version: trusty
62+
playbook: stable
63+
- distribution: ubuntu
64+
version: trusty
65+
playbook: push
66+
- distribution: ubuntu
67+
version: xenial
68+
playbook: basic
69+
- distribution: ubuntu
70+
version: xenial
71+
playbook: template
72+
- distribution: ubuntu
73+
version: xenial
74+
playbook: stable
75+
- distribution: ubuntu
76+
version: xenial
77+
playbook: push
78+
before_install:
79+
- 'sudo docker pull ${distribution}:${version}'
80+
- 'sudo docker build --no-cache --rm --file=tests/dockerfiles/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
1881
script:
19-
# Basic role syntax check
20-
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
21-
# Run the role with ansible-playbook.
22-
- ansible-playbook tests/test.yml -i tests/inventory --connection=local --sudo
23-
# Run the role again, checking to make sure it's idempotent.
82+
- container_id=$(mktemp)
83+
- 'sudo docker run --detach --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro --volume="${PWD}":/etc/ansible/roles/ansible-role-nginx:ro ${distribution}-${version}:ansible > "${container_id}"'
84+
- 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${playbook}.yml --syntax-check'
85+
- 'sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${playbook}.yml'
2486
- >
25-
ansible-playbook tests/test.yml -i tests/inventory --connection=local --sudo | grep -q 'changed=0.*failed=0'
26-
&& (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)
27-
# Request a page via the web server, to make sure NGINX is running and responds.
28-
- curl http://localhost/
87+
sudo docker exec "$(cat ${container_id})" env ANSIBLE_FORCE_COLOR=1 ansible-playbook -v /etc/ansible/roles/ansible-role-nginx/tests/playbooks/nginx-${playbook}.yml
88+
| grep -q 'changed=0.*failed=0'
89+
&& (echo 'Idempotence test: pass' && exit 0)
90+
|| (echo 'Idempotence test: fail' && exit 1)
91+
- 'sudo docker exec "$(cat ${container_id})" curl http://localhost/'
92+
- 'sudo docker rm -f "$(cat ${container_id})"'
2993
notifications:
3094
webhooks: https://galaxy.ansible.com/api/v1/notifications/

README.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Ansible NGINX Role
44
[![Ansible Galaxy](https://img.shields.io/badge/galaxy-nginxinc.nginx-5bbdbf.svg)](https://galaxy.ansible.com/nginxinc/nginx)
55
[![Build Status](https://travis-ci.org/nginxinc/ansible-role-nginx.svg?branch=master)](https://travis-ci.org/nginxinc/ansible-role-nginx)
66

7-
This role installs open source NGINX, NGINX Plus, or NGINX Unit on your target host.
7+
This role installs NGINX Open Source, NGINX Plus, or NGINX Unit on your target host.
88

99
Requirements
1010
------------
@@ -13,9 +13,9 @@ This role was developed using Ansible 2.4.0.0. Backwards compatibility is not gu
1313

1414
Use `ansible-galaxy install nginxinc.nginx` to install the role on your system.
1515

16-
It supports all platforms supported by [open source NGINX](https://nginx.org/en/linux_packages.html#mainline) and [NGINX Plus](https://www.nginx.com/products/technical-specs/):
16+
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/):
1717

18-
**Open Source NGINX:**
18+
**NGINX Open Source:**
1919

2020
CentOS:
2121
versions:
@@ -106,8 +106,27 @@ This role has multiple variables. The defaults for all these variables are the f
106106
# Default is 'opensource'.
107107
type: opensource
108108

109-
# Specify which branch of Open Source NGINX you want to install.
109+
# Specify repository origin for NGINX Open Source.
110+
# Options are 'nginx_repository' or 'os_repository'.
111+
# Only works if 'type' is set to 'opensource'.
112+
# Default is nginx_repository.
113+
install_from: nginx_repository
114+
115+
# Specify source repository for NGINX Open Source.
116+
# Only works if 'install_from' is set to 'nginx_repository'.
117+
# Defaults are the official NGINX repositories.
118+
nginx_repository:
119+
debian:
120+
- 'deb https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx'
121+
- 'deb-src https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx'
122+
redhat:
123+
- https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}{{ ansible_distribution_major_version|int }}/$basearch/
124+
suse:
125+
- https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}sles/12
126+
127+
# Specify which branch of NGINX Open Source you want to install.
110128
# Options are 'mainline' or 'stable'.
129+
# Only works if 'install_from' is set to 'nginx_repository'.
111130
# Default is mainline.
112131
branch: mainline
113132

@@ -116,8 +135,7 @@ This role has multiple variables. The defaults for all these variables are the f
116135
unit_enable: false
117136
unit_packages: false
118137

119-
# Install nginscript, perl, waf (NGINX Plus only), geoip, image-filter, rtmp and/or xslt modules.
120-
# Default is false.
138+
# Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules. # Default is false.
121139
modules:
122140
njs: false
123141
perl: false
@@ -134,18 +152,15 @@ This role has multiple variables. The defaults for all these variables are the f
134152
amplify_key: null
135153

136154
# Enable NGINX status data.
137-
# Will enable 'stub_status' in open source NGINX and 'status' in NGINX Plus.
155+
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
138156
# Default is false.
139157
status_enable: false
140158

141-
# Enable NGINX Plus REST API and write access.
159+
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
142160
# Default is false.
143161
rest_api_enable: false
144162
rest_api_write: false
145-
146-
# Enable NGINX Plus dashboard. REST API also needs to be enabled.
147-
# Default is false.
148-
dashboard: false
163+
rest_api_dashboard: false
149164

150165
# Location of your NGINX Plus license in your local machine.
151166
# Default is the files folder within the NGINX Ansible role.
@@ -170,8 +185,8 @@ This role has multiple variables. The defaults for all these variables are the f
170185
main_template_worker_processes: auto
171186
main_template_error_level: warn
172187
main_template_worker_connections: 1024
173-
main_template_keepalive_timeout: 65
174188
http_template_enable: false
189+
http_template_keepalive_timeout: 65
175190
http_template_listen: 80
176191
http_template_server_name: localhost
177192
stream_template_enable: false

defaults/main.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,27 @@
44
# Default is 'opensource'.
55
type: opensource
66

7-
# Specify which branch of Open Source NGINX you want to install.
7+
# Specify repository origin for NGINX Open Source.
8+
# Options are 'nginx_repository' or 'os_repository'.
9+
# Only works if 'type' is set to 'opensource'.
10+
# Default is nginx_repository.
11+
install_from: nginx_repository
12+
13+
# Specify source repository for NGINX Open Source.
14+
# Only works if 'install_from' is set to 'nginx_repository'.
15+
# Defaults are the official NGINX repositories.
16+
nginx_repository:
17+
debian:
18+
- deb https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx
19+
- deb-src https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx
20+
redhat:
21+
- https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}{{ ansible_distribution_major_version|int }}/$basearch/
22+
suse:
23+
- https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}sles/12
24+
25+
# Specify which branch of NGINX Open Source you want to install.
826
# Options are 'mainline' or 'stable'.
27+
# Only works if 'install_from' is set to 'nginx_repository'.
928
# Default is mainline.
1029
branch: mainline
1130

@@ -14,7 +33,7 @@ branch: mainline
1433
unit_enable: false
1534
unit_packages: false
1635

17-
# Install nginscript, perl, waf (NGINX Plus only), geoip, image-filter, rtmp and/or xslt modules.
36+
# Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules.
1837
# Default is false.
1938
modules:
2039
njs: false
@@ -32,18 +51,15 @@ amplify_enable: false
3251
amplify_key: null
3352

3453
# Enable NGINX status data.
35-
# Will enable 'stub_status' in open source NGINX and 'status' in NGINX Plus.
54+
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.
3655
# Default is false.
3756
status_enable: false
3857

39-
# Enable NGINX Plus REST API and write access.
58+
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
4059
# Default is false.
4160
rest_api_enable: false
4261
rest_api_write: false
43-
44-
# Enable NGINX Plus dashboard. REST API also needs to be enabled.
45-
# Default is false.
46-
dashboard: false
62+
rest_api_dashboard: false
4763

4864
# Location of your NGINX Plus license in your local machine.
4965
# Default is the files folder within the NGINX Ansible role.
@@ -68,8 +84,8 @@ main_template_user: nginx
6884
main_template_worker_processes: auto
6985
main_template_error_level: warn
7086
main_template_worker_connections: 1024
71-
main_template_keepalive_timeout: 65
7287
http_template_enable: false
88+
http_template_keepalive_timeout: 65
7389
http_template_listen: 80
7490
http_template_server_name: localhost
7591
stream_template_enable: false

tasks/conf/push-config.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
---
22
- name: "(Setup: All NGINX) Upload NGINX Main Configuration File"
33
copy:
4-
src: "{{ main_upload_location }}"
4+
src: "{{ main_push_location }}"
55
dest: /etc/nginx/nginx.conf
6+
backup: yes
67
notify: "(Handler: All OSs) Reload NGINX"
7-
when: main_upload_enable
8+
when: main_push_enable
9+
10+
- name: "(Setup: All NGINX) Ensure NGINX HTTP Directory Exists"
11+
file:
12+
path: /etc/nginx/conf.d/http
13+
state: directory
14+
when: http_push_enable
815

916
- name: "(Setup: All NGINX) Upload NGINX HTTP Configuration Files"
1017
copy:
1118
src: "{{ item }}"
12-
dest: /etc/nginx/conf.d/
19+
dest: /etc/nginx/conf.d/http
20+
backup: yes
1321
with_fileglob:
14-
- "{{ http_upload_location }}"
22+
- "{{ http_push_location }}"
1523
notify: "(Handler: All OSs) Reload NGINX"
16-
when: http_upload_enable
24+
when: http_push_enable
25+
26+
- name: "(Setup: All NGINX) Ensure NGINX Stream Directory Exists"
27+
file:
28+
path: /etc/nginx/conf.d/stream
29+
state: directory
30+
when: stream_push_enable
1731

1832
- name: "(Setup: All NGINX) Upload NGINX Stream Configuration Files"
1933
copy:
2034
src: "{{ item }}"
21-
dest: /etc/nginx/conf.d/
35+
dest: /etc/nginx/conf.d/stream
36+
backup: yes
2237
with_fileglob:
23-
- "{{ stream_upload_location }}"
38+
- "{{ stream_push_location }}"
2439
notify: "(Handler: All OSs) Reload NGINX"
25-
when: stream_upload_enable
40+
when: stream_push_enable

tasks/conf/setup-rest-api.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
---
22
- name: "(Setup: NGINX Plus) Setup NGINX Plus API"
3-
template:
4-
src: api.conf.j2
5-
dest: "{{ (http_template_enable) | ternary('/etc/nginx/conf.d/http/api.conf','/etc/nginx/conf.d/api.conf') }}"
3+
blockinfile:
4+
path: "{{ (http_template_enable) | ternary('/etc/nginx/conf.d/http/api.conf','/etc/nginx/conf.d/api.conf') }}"
5+
create: yes
6+
block: |
7+
server {
8+
listen 8080;
9+
location /api {
10+
{% if rest_api_write %}
11+
api write=on;
12+
{% else %}
13+
api;
14+
{% endif %}
15+
}
16+
{% if rest_api_dashboard %}
17+
location = /dashboard.html {
18+
root /usr/share/nginx/html;
19+
}
20+
{% endif %}
21+
}
622
notify: "(Handler: All OSs) Reload NGINX"

tasks/conf/setup-status.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
- name: "(Setup: Open Source NGINX) Enable Open Source NGINX Status"
2+
- name: "(Setup: NGINX Open Source) Enable NGINX Open Source Status"
33
blockinfile:
4-
path: /etc/nginx/conf.d/stub_status.conf
4+
path: "{{ (http_template_enable) | ternary('/etc/nginx/conf.d/http/stub_status.conf','/etc/nginx/conf.d/stub_status.conf') }}"
55
create: yes
66
block: |
77
server {
@@ -17,7 +17,7 @@
1717

1818
- name: "(Setup: NGINX Plus) Enable NGINX Plus Status"
1919
blockinfile:
20-
path: /etc/nginx/conf.d/status.conf
20+
path: "{{ (http_template_enable) | ternary('/etc/nginx/conf.d/http/status.conf','/etc/nginx/conf.d/status.conf') }}"
2121
create: yes
2222
block: |
2323
server {

0 commit comments

Comments
 (0)