Skip to content

Commit 970320b

Browse files
authored
Fix and improve stub status and REST API templating (#41)
1 parent c88b47b commit 970320b

File tree

8 files changed

+69
-39
lines changed

8 files changed

+69
-39
lines changed

CHANGELOG.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
# Changelog
22

3-
## 0.3.0 (Unreleased)
3+
## 0.3.0 (November 17, 2020)
44

55
BREAKING CHANGES:
66

7-
* The default port of the status module is now 8080 and matches the CI molecule test which already used it. Set ```nginx_config_status_port```to another desired value.
7+
The default port of the status module is now 8080 and matches the CI molecule test which already used it. Set `nginx_config_status_port` to another desired value.
88

99
ENHANCEMENTS:
1010

1111
* Add survey to README.
1212
* Improve README structure and use tables where relevant.
1313
* Update Ansible (now Ansible base) to `2.10.3`, Ansible (now Ansible Community Distribution) to `2.10.3`, Ansible Lint to `4.3.7`, Molecule to `3.1.5`, and yamllint to `1.25.0`.
14+
* Improve templating of stub status and REST API config.
1415

1516
BUG FIXES:
1617

1718
* Prevent TravisCI from trying to build (and failing) NGINX Plus images on external PRs.
18-
* Fix naming for SELinux Ansible facts.
19+
* Fix naming for SELinux facts dictionary.
1920
* Correctly import `app_protect` global directives in template.
2021
* Role now runs correctly when using Ansible's check mode.
22+
* Fix issue with access log in stub status and REST API config template not being properly parsed.
2123

2224
## 0.2.0 (September 24, 2020)
2325

2426
BREAKING CHANGES:
2527

26-
* The process to configure modules has changed. Instead of manually setting the modules you want to install to `true` or `false`, you will now have to use either:
27-
* A newly introduced top level list variable, `nginx_config_modules`.
28-
* A newly introduced list variable within your main NGINX config template, `nginx_config_main_template.modules`.
28+
The process to configure modules has changed. Instead of manually setting the modules you want to install to `true` or `false`, you will now have to use either:
29+
* A newly introduced top level list variable, `nginx_config_modules`.
30+
* A newly introduced list variable within your main NGINX config template, `nginx_config_main_template.modules`.
2931

3032
Make sure you only use one variable or the other, since they will overwrite each other. This change will simplify adding future supported modules to this role, and allows you to include any external modules you may wish in your NGINX config.
3133

@@ -49,7 +51,7 @@ ENHANCEMENTS:
4951

5052
BUG FIXES:
5153

52-
* An empty `nginx_config_cleanup_files` will no longer cause `nginx_config_cleanup` related tasks to fail.
54+
An empty `nginx_config_cleanup_files` will no longer cause `nginx_config_cleanup` related tasks to fail.
5355

5456
## 0.1.0 (August 19, 2020)
5557

defaults/main/template.yml

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,25 +360,35 @@ nginx_config_http_template:
360360
nginx_config_status_enable: false
361361
nginx_config_status_template_file: http/status.conf.j2
362362
nginx_config_status_file_location: /etc/nginx/conf.d/status.conf
363-
nginx_config_status_log: false
364-
nginx_config_status_port: 8080
365-
nginx_config_status_allow: 127.0.0.1
366-
nginx_config_status_deny: all
363+
nginx_config_status_port: 8080 # Optional -- Defaults to 8080
364+
nginx_config_status_access_log: # Optional -- Set to 'false' to disable access log
365+
location: /var/log/nginx/access.log # Required
366+
name: main # Required
367+
nginx_config_status_allow: # Optional
368+
- 127.0.0.1
369+
nginx_config_status_deny: # Optional
370+
- all
367371

368372
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
369373
# Requires NGINX Plus.
370374
# Default is false.
371375
nginx_config_rest_api_enable: false
372376
nginx_config_rest_api_template_file: http/api.conf.j2
373377
nginx_config_rest_api_file_location: /etc/nginx/conf.d/api.conf
374-
nginx_config_rest_api_log: false
375-
nginx_config_rest_api_port: 80
376-
nginx_config_rest_api_write: false
377-
nginx_config_rest_api_dashboard: false
378-
nginx_config_rest_api_allow: 127.0.0.1
379-
nginx_config_rest_api_deny: all
380-
nginx_config_rest_api_dashboard_allow: 127.0.0.1
381-
nginx_config_rest_api_dashboard_deny: all
378+
nginx_config_rest_api_port: 8080 # Optional-- Defaults to 8080
379+
nginx_config_rest_api_write: false # Optional
380+
nginx_config_rest_api_access_log: # Optional -- Set to 'false' to disable access log
381+
location: /var/log/nginx/access.log # Required
382+
name: main # Required
383+
nginx_config_rest_api_allow: # Optional
384+
- 127.0.0.1
385+
nginx_config_rest_api_deny: # Optional
386+
- all
387+
nginx_config_rest_api_dashboard: false # Optional
388+
nginx_config_rest_api_dashboard_allow: # Optional
389+
- 127.0.0.1
390+
nginx_config_rest_api_dashboard_deny: # Optional
391+
- all
382392

383393
# Enable creating dynamic templated NGINX stream configuration files.
384394
# Defaults will not produce a valid configuration. Instead they are meant to showcase
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
roles:
33
- name: nginxinc.nginx
4-
version: 0.17.2
4+
version: 0.18.1
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
roles:
33
- name: nginxinc.nginx
4-
version: 0.17.2
4+
version: 0.18.1
55
- name: nginxinc.nginx_app_protect
6-
version: 0.3.1
6+
version: 0.4.1

molecule/default/converge.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
name: ansible-role-nginx-config
88
vars:
99
nginx_config_debug_output: true
10+
1011
nginx_config_selinux: true
1112
nginx_config_selinux_tcp_ports:
1213
- 80
@@ -58,7 +59,9 @@
5859

5960
nginx_config_status_enable: true
6061
nginx_config_status_port: 8080
61-
nginx_config_status_log: true
62+
nginx_config_status_access_log:
63+
location: /var/log/nginx/access.log
64+
name: main
6265

6366
nginx_config_http_template_enable: true
6467
nginx_config_http_template:

molecule/plus/converge.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@
6464
stream_enable: true
6565

6666
nginx_config_rest_api_enable: true
67-
nginx_config_rest_api_write: true
68-
nginx_config_rest_api_dashboard: true
67+
nginx_config_rest_api_write: false
68+
nginx_config_rest_api_access_log: false
69+
nginx_config_rest_api_dashboard: false
6970

7071
nginx_config_http_template_enable: true
7172
nginx_config_http_template:

templates/http/api.conf.j2

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
{{ ansible_managed | comment }}
22

33
server {
4-
listen {{ nginx_config_rest_api_port | default('80') }};
5-
access_log {{ nginx_config_rest_api_log | ternary('on', 'off') }};
4+
listen {{ nginx_config_rest_api_port | default('8080') }};
5+
{% if nginx_config_rest_api_access_log is defined %}
6+
access_log{{ ' off' if not nginx_config_rest_api_access_log }}{{ (' ' + nginx_config_rest_api_access_log.location) if nginx_config_rest_api_access_log.location is defined }}{{ (' ' + nginx_config_rest_api_access_log.name) if nginx_config_status_rest_api_log.name is defined }};
7+
{% endif %}
68
location /api {
7-
{% if nginx_config_rest_api_write %}
8-
api write=on;
9-
{% else %}
10-
api;
9+
{% if nginx_config_rest_api_write is defined %}
10+
api{{ ' write=on' if nginx_config_rest_api_write }};
1111
{% endif %}
1212
{% if nginx_config_rest_api_allow is defined %}
13-
allow {{ nginx_config_rest_api_allow }};
13+
{% for address in nginx_config_rest_api_allow %}
14+
allow {{ address }};
15+
{% endfor %}
1416
{% endif %}
1517
{% if nginx_config_rest_api_deny is defined %}
16-
deny {{ nginx_config_rest_api_deny }};
18+
{% for address in nginx_config_rest_api_deny %}
19+
deny {{ address }};
20+
{% endfor %}
1721
{% endif %}
1822
}
19-
{% if nginx_config_rest_api_dashboard %}
23+
{% if nginx_config_rest_api_dashboard is defined and nginx_config_rest_api_dashboard %}
2024
location = /dashboard.html {
2125
root /usr/share/nginx/html;
2226
{% if nginx_config_rest_api_dashboard_allow is defined %}
23-
allow {{ nginx_config_rest_api_dashboard_allow }};
27+
{% for address in nginx_config_rest_api_dashboard_allow %}
28+
allow {{ address }};
29+
{% endfor %}
2430
{% endif %}
2531
{% if nginx_config_rest_api_dashboard_deny is defined %}
26-
deny {{ nginx_config_rest_api_dashboard_deny }};
32+
{% for address in nginx_config_rest_api_dashboard_deny %}
33+
deny {{ address }};
34+
{% endfor %}
2735
{% endif %}
2836
}
2937
{% endif %}

templates/http/status.conf.j2

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
server {
44
listen {{ nginx_config_status_port | default('8080') }};
5-
access_log {{ nginx_config_status_log | ternary('on', 'off') }};
5+
{% if nginx_config_status_access_log is defined %}
6+
access_log{{ ' off' if not nginx_config_status_access_log }}{{ (' ' + nginx_config_status_access_log.location) if nginx_config_status_access_log.location is defined }}{{ (' ' + nginx_config_status_access_log.name) if nginx_config_status_access_log.name is defined }};
7+
{% endif %}
68
location /nginx_status {
79
stub_status on;
810
}
911
{% if nginx_config_status_allow is defined %}
10-
allow {{ nginx_config_status_allow }};
12+
{% for address in nginx_config_status_allow %}
13+
allow {{ address }};
14+
{% endfor %}
1115
{% endif %}
1216
{% if nginx_config_status_deny is defined %}
13-
deny {{ nginx_config_status_deny }};
17+
{% for address in nginx_config_status_deny%}
18+
deny {{ address }};
19+
{% endfor %}
1420
{% endif %}
1521
}

0 commit comments

Comments
 (0)