Skip to content

Commit b7e2596

Browse files
authored
Refactor status templating (#288)
1 parent 838e756 commit b7e2596

File tree

8 files changed

+76
-59
lines changed

8 files changed

+76
-59
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ BREAKING CHANGES:
66

77
* The Debian and Ubuntu repositories have slightly changed. You may run into some duplication issues when running the role on a preexisting target that already has had NGINX installed using the role. To fix this, manually remove the old repository source.
88
* If you use `custom_options` you will now need to manually end each directive with a semicolon.
9+
* The `status` directive is no longer supported in NGINX Plus, and the `stub_status` directive has been reworked into a template.
910
* The listen directive structure in the `stream` template has been updated to the listen directive structure found in the `http` template. You can now specify multiple `listen` directives in the same `server` block as well as include any extra `listen` options you might need.
1011

1112
Old configuration example

defaults/main/template.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,27 @@ nginx_http_template:
317317
# Note - 'status' has been deprecated since NGINX Plus R13.
318318
# Default is false.
319319
nginx_status_enable: false
320-
nginx_status_location: /etc/nginx/conf.d/stub_status.conf
321-
nginx_status_port: 80
320+
nginx_status_template_file: http/status.conf.j2
321+
nginx_status_file_location: /etc/nginx/conf.d/status.conf
322322
nginx_status_log: false
323+
nginx_status_port: 80
324+
nginx_status_allow: 127.0.0.1
325+
nginx_status_deny: all
323326

324327
# Enable NGINX Plus REST API, write access to the REST API, and NGINX Plus dashboard.
325328
# Requires NGINX Plus.
326329
# Default is false.
327330
nginx_rest_api_enable: false
328331
nginx_rest_api_template_file: http/api.conf.j2
329332
nginx_rest_api_file_location: /etc/nginx/conf.d/api.conf
330-
nginx_rest_api_port: 80
331333
nginx_rest_api_log: false
334+
nginx_rest_api_port: 80
332335
nginx_rest_api_write: false
333336
nginx_rest_api_dashboard: false
337+
nginx_status_rest_api_allow: 127.0.0.1
338+
nginx_status_rest_api_deny: all
339+
nginx_status_rest_api_dashboard_allow: 127.0.0.1
340+
nginx_status_rest_api_dashboard_deny: all
334341

335342
# Enable creating dynamic templated NGINX stream configuration files.
336343
# Defaults will not produce a valid configuration. Instead they are meant to showcase

molecule/common/playbooks/template_converge.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
stream_enable: true
5959

6060
nginx_status_enable: true
61-
nginx_status_location: /etc/nginx/conf.d/stub_status.conf
6261
nginx_status_port: 8080
6362
nginx_status_log: true
6463

tasks/conf/setup-status.yml

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

tasks/conf/template-config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
when: nginx_http_template_enable | bool
5656
notify: "(Handler: All OSs) Reload NGINX"
5757

58+
- name: "(Setup: All NGINX) Dynamically Generate NGINX Stub Status Configuration File"
59+
template:
60+
src: "{{ nginx_status_template_file | default('http/status.conf.j2') }}"
61+
dest: "{{ nginx_status_file_location | default('/etc/nginx/conf.d/status.conf') }}"
62+
backup: yes
63+
notify: "(Handler: All OSs) Reload NGINX"
64+
when: nginx_status_enable | bool
65+
5866
- name: "(Setup: All NGINX) Dynamically Generate NGINX API Configuration File"
5967
template:
6068
src: "{{ nginx_rest_api_template_file | default('http/api.conf.j2') }}"

tasks/main.yml

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
- name: "(Setup: Prerequisites)"
2+
- name: "(Setup: All OSs) Setup Prerequisites"
33
include_tasks: "{{ role_path }}/tasks/prerequisites/setup-{{ ansible_os_family | lower }}.yml"
44
tags: nginx_prerequisites
55

6-
- name: "(Setup: Keys)"
6+
- name: "(Setup: All OSs) Setup Keys"
77
import_tasks: keys/setup-keys.yml
88
when:
99
- ansible_os_family == "Alpine"
@@ -15,73 +15,82 @@
1515
or nginx_unit_enable
1616
tags: nginx_key
1717

18-
- name: "(Install: Debian/Ubuntu/CentOS/RedHat/FreeBSD) Install NGINX"
18+
- name: "(Install/Config: All OSs) Install and Configure NGINX"
1919
block:
2020

21-
- block:
22-
- include_tasks: "{{ role_path }}/tasks/opensource/install-oss.yml"
21+
- name: "(Install: All OSs) Install NGINX"
22+
block:
23+
- name: "(Install: All OSs) Install NGINX Open Source"
24+
include_tasks: "{{ role_path }}/tasks/opensource/install-oss.yml"
2325
when: nginx_type == "opensource"
2426
tags: nginx_install_oss
2527

26-
- include_tasks: "{{ role_path }}/tasks/plus/install-plus.yml"
28+
- name: "(Install: All OSs) Install NGINX Plus"
29+
include_tasks: "{{ role_path }}/tasks/plus/install-plus.yml"
2730
when: nginx_type == "plus"
2831
tags: nginx_install_plus
2932

30-
- include_tasks: "{{ role_path }}/tasks/modules/install-modules.yml"
33+
- name: "(Install: All OSs) Install NGINX Modules"
34+
include_tasks: "{{ role_path }}/tasks/modules/install-modules.yml"
3135
when: true in nginx_modules.values()
3236
tags: nginx_install_modules
3337

34-
- include_tasks: "{{ role_path }}/tasks/plus/delete-license.yml"
38+
- name: "(Install: All OSs) Delete NGINX Plus License"
39+
include_tasks: "{{ role_path }}/tasks/plus/delete-license.yml"
3540
when:
3641
- nginx_type == "plus"
3742
- nginx_delete_license
3843
tags: nginx_delete_license
3944
when: nginx_install | bool
4045

41-
- block:
42-
- include_tasks: "{{ role_path }}/tasks/conf/cleanup-config.yml"
46+
- name: "(Config: All OSs) Configure NGINX"
47+
block:
48+
- name: "(Config: All OSs) Cleanup NGINX Config"
49+
include_tasks: "{{ role_path }}/tasks/conf/cleanup-config.yml"
4350
when: nginx_cleanup_config | bool
4451
tags: nginx_cleanup_config
4552

46-
- include_tasks: "{{ role_path }}/tasks/conf/upload-config.yml"
53+
- name: "(Config: All OSs) Upload NGINX Config"
54+
include_tasks: "{{ role_path }}/tasks/conf/upload-config.yml"
4755
when: nginx_main_upload_enable
4856
or nginx_http_upload_enable
4957
or nginx_stream_upload_enable
5058
or nginx_html_upload_enable
5159
or nginx_ssl_upload_enable
5260
tags: nginx_upload_config
5361

54-
- include_tasks: "{{ role_path }}/tasks/conf/template-config.yml"
62+
- name: "(Config: All OSs) Create NGINX Config"
63+
include_tasks: "{{ role_path }}/tasks/conf/template-config.yml"
5564
when: nginx_main_template_enable
5665
or nginx_http_template_enable
5766
or nginx_stream_template_enable
5867
or nginx_rest_api_enable
5968
tags: nginx_template_config
60-
61-
- include_tasks: "{{ role_path }}/tasks/conf/setup-status.yml"
62-
when: nginx_status_enable | bool
63-
tags: nginx_setup_status
6469
when: nginx_configure | bool
6570

6671
- name: "(Config: All OSs) Ensure NGINX is Running"
6772
meta: flush_handlers
6873

69-
- include_tasks: "{{ role_path }}/tasks/conf/debug-output.yml"
74+
- name: "(Config: All OSs) Debug Output"
75+
include_tasks: "{{ role_path }}/tasks/conf/debug-output.yml"
7076
when: nginx_debug_output | bool
7177
tags: nginx_debug_output
7278

73-
- include_tasks: "{{ role_path }}/tasks/conf/logrotate.yml"
79+
- name: "(Config: All OSs): Configure Logrotate"
80+
include_tasks: "{{ role_path }}/tasks/conf/logrotate.yml"
7481
when: nginx_logrotate_conf_enable | bool
7582
tags: nginx_logrotate_config
7683
when: nginx_enable | bool
7784

78-
- include_tasks: "{{ role_path }}/tasks/amplify/install-amplify.yml"
85+
- name: "(Install: All OSs) Install NGINX Amplify"
86+
include_tasks: "{{ role_path }}/tasks/amplify/install-amplify.yml"
7987
when:
8088
- nginx_amplify_enable | bool
8189
- nginx_amplify_api_key is defined
8290
- nginx_amplify_api_key | length > 0
8391
tags: nginx_install_amplify
8492

85-
- include_tasks: "{{ role_path }}/tasks/unit/install-unit.yml"
93+
- name: "(Install: All OSs) Install NGINX Unit"
94+
include_tasks: "{{ role_path }}/tasks/unit/install-unit.yml"
8695
when: nginx_unit_enable | bool
8796
tags: nginx_install_unit

templates/http/api.conf.j2

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,29 @@
22

33
server {
44
listen {{ nginx_rest_api_port | default('80') }};
5-
access_log {{ nginx_rest_api_log | ternary("on", "off") }};
5+
access_log {{ nginx_rest_api_log | ternary('on', 'off') }};
66
location /api {
77
{% if nginx_rest_api_write %}
88
api write=on;
99
{% else %}
1010
api;
11+
{% endif %}
12+
{% if nginx_status_rest_api_allow is defined %}
13+
allow {{ nginx_status_rest_api_allow }};
14+
{% endif %}
15+
{% if nginx_status_rest_api_deny is defined %}
16+
deny {{ nginx_status_rest_api_deny }};
1117
{% endif %}
1218
}
1319
{% if nginx_rest_api_dashboard %}
1420
location = /dashboard.html {
1521
root /usr/share/nginx/html;
22+
{% if nginx_status_rest_api_dashboard_allow is defined %}
23+
allow {{ nginx_status_rest_api_dashboard_allow }};
24+
{% endif %}
25+
{% if nginx_status_rest_api_dashboard_deny is defined %}
26+
deny {{ nginx_status_rest_api_dashboard_deny }};
27+
{% endif %}
1628
}
1729
{% endif %}
1830
}

templates/http/status.conf.j2

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{ ansible_managed | comment }}
2+
3+
server {
4+
listen {{ nginx_status_port | default('80') }};
5+
access_log {{ nginx_status_log | ternary('on', 'off') }};
6+
location /nginx_status {
7+
stub_status on;
8+
{% if nginx_status_allow is defined %}
9+
allow {{ nginx_status_allow }};
10+
{% endif %}
11+
{% if nginx_status_deny is defined %}
12+
deny {{ nginx_status_deny }};
13+
{% endif %}
14+
}
15+
}

0 commit comments

Comments
 (0)