Skip to content

Commit 903693e

Browse files
authored
Refactor handlers (#321)
1 parent 28d1da5 commit 903693e

18 files changed

+53
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ FEATURES:
2020

2121
ENHANCEMENTS:
2222

23+
* Added handlers to check for NGINX syntax validity and fail if any errors are detected.
2324
* Major backend refactoring to reduce the number of files and tasks.
2425
* You can now specify an `nginx_repository` for NGINX Plus too.
2526
* Moved "constant" variables to `vars/main.yml`.

handlers/main.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
---
22
- name: "(Handler) Check NGINX"
33
command: "nginx -t"
4-
changed_when: false
4+
register: config
5+
ignore_errors: yes
6+
listen: "(Handler) Run NGINX"
57

6-
- name: "(Handler) Systemd Daemon-Reload"
8+
- name: "(Handler) Print NGINX error if syntax check fails"
9+
fail:
10+
msg: "{{ config.stderr }}"
11+
when: config.rc != 0
12+
listen: "(Handler) Run NGINX"
13+
14+
- name: "(Handler) Systemd daemon-reload"
715
systemd:
816
daemon_reload: yes
9-
notify: "(Handler) Start NGINX"
10-
11-
- name: "(Handler) Run NGINX"
12-
block:
13-
- name: "(Handler) Start NGINX"
14-
service:
15-
name: nginx
16-
state: started
17-
enabled: yes
18-
notify: "(Handler) Check NGINX"
1917

20-
- name: "(Handler) Reload NGINX"
21-
command: "nginx -s reload"
22-
changed_when: false
18+
- name: "(Handler) Start/Reload NGINX"
19+
service:
20+
name: nginx
21+
state: reloaded
22+
enabled: yes
2323
when:
2424
- nginx_start | bool
2525
- not ansible_check_mode | bool
26+
listen: "(Handler) Run NGINX"
2627

2728
- name: "(Handler) Start NGINX Amplify agent"
2829
service:

tasks/config/modify-systemd.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
when:
2121
- not nginx_service_custom | bool
2222
- not nginx_service_clean | bool
23-
notify: "(Handler) Systemd Daemon-Reload"
23+
notify: "(Handler) Systemd daemon-reload"
2424

2525
- name: "Customize override for NGINX systemd service"
2626
copy:
@@ -32,14 +32,14 @@
3232
when:
3333
- nginx_service_custom | bool
3434
- not nginx_service_clean | bool
35-
notify: "(Handler) Systemd Daemon-Reload"
35+
notify: "(Handler) Systemd daemon-reload"
3636

3737
- name: "Remove override for NGINX systemd service"
3838
file:
3939
path: "{{ nginx_service_overridepath }}"
4040
state: absent
4141
when: nginx_service_clean | bool
42-
notify: "(Handler) Systemd Daemon-Reload"
42+
notify: "(Handler) Systemd daemon-reload"
4343

4444
- name: "Modify systemd"
4545
debug:

tasks/config/template-config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
backup: yes
3636
mode: 0644
3737
when: nginx_main_template_enable | bool
38-
notify: "(Handler) Reload NGINX"
38+
notify: "(Handler) Run NGINX"
3939

4040
- name: "(DEPRECATED) Ensure NGINX HTTP Directory Exists"
4141
file:
@@ -65,7 +65,7 @@
6565
mode: 0644
6666
with_dict: "{{ nginx_http_template }}"
6767
when: nginx_http_template_enable | bool
68-
notify: "(Handler) Reload NGINX"
68+
notify: "(Handler) Run NGINX"
6969

7070
- name: "(DEPRECATED) Dynamically Generate NGINX Stub Status Configuration File"
7171
template:
@@ -74,7 +74,7 @@
7474
backup: yes
7575
mode: 0644
7676
when: nginx_status_enable | bool
77-
notify: "(Handler) Reload NGINX"
77+
notify: "(Handler) Run NGINX"
7878

7979
- name: "(DEPRECATED) Dynamically Generate NGINX API Configuration File"
8080
template:
@@ -83,7 +83,7 @@
8383
backup: yes
8484
mode: 0644
8585
when: nginx_rest_api_enable | bool
86-
notify: "(Handler) Reload NGINX"
86+
notify: "(Handler) Run NGINX"
8787

8888
- name: "(DEPRECATED) Ensure NGINX Stream Directory Exists"
8989
file:
@@ -101,4 +101,4 @@
101101
mode: 0644
102102
with_dict: "{{ nginx_stream_template }}"
103103
when: nginx_stream_template_enable | bool
104-
notify: "(Handler) Reload NGINX"
104+
notify: "(Handler) Run NGINX"

tasks/config/upload-config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
mode: 0644
2020
with_fileglob: "{{ nginx_html_upload_src }}"
2121
when: nginx_html_upload_enable | bool
22-
notify: "(Handler) Reload NGINX"
22+
notify: "(Handler) Run NGINX"
2323

2424
- name: "(DEPRECATED) Ensure NGINX Main Directory Exists"
2525
file:
@@ -35,7 +35,7 @@
3535
backup: yes
3636
mode: 0644
3737
when: nginx_main_upload_enable | bool
38-
notify: "(Handler) Reload NGINX"
38+
notify: "(Handler) Run NGINX"
3939

4040
- name: "(DEPRECATED) Ensure NGINX HTTP Directory Exists"
4141
file:
@@ -52,7 +52,7 @@
5252
mode: 0644
5353
with_fileglob: "{{ nginx_http_upload_src }}"
5454
when: nginx_http_upload_enable | bool
55-
notify: "(Handler) Reload NGINX"
55+
notify: "(Handler) Run NGINX"
5656

5757
- name: "(DEPRECATED) Ensure NGINX Stream Directory Exists"
5858
file:
@@ -69,7 +69,7 @@
6969
mode: 0644
7070
with_fileglob: "{{ nginx_stream_upload_src }}"
7171
when: nginx_stream_upload_enable | bool
72-
notify: "(Handler) Reload NGINX"
72+
notify: "(Handler) Run NGINX"
7373

7474
- name: "(DEPRECATED) Ensure SSL Certificate Directory Exists"
7575
file:

tasks/opensource/install-alpine.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
repository: "{{ repository }}"
1212
state: "{{ nginx_state }}"
1313
update_cache: yes
14-
notify: "(Handler) Start NGINX"
14+
notify: "(Handler) Run NGINX"

tasks/opensource/install-bsd.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
name: "www/nginx{{ nginx_version | default('') }}"
2222
state: "{{ nginx_state }}"
2323
when: nginx_bsd_install_packages | bool
24-
notify: "(Handler) Start NGINX"
24+
notify: "(Handler) Run NGINX"
2525

2626
- name: "(FreeBSD) Install NGINX port"
2727
portinstall:
2828
name: "www/nginx{{ nginx_version | default('') }}"
2929
use_packages: "{{ nginx_bsd_portinstall_use_packages | default(omit) }}"
3030
state: "{{ nginx_state }}"
3131
when: not nginx_bsd_install_packages | bool
32-
notify: "(Handler) Start NGINX"
32+
notify: "(Handler) Run NGINX"
3333
when: ansible_facts['system'] == "FreeBSD"
3434

3535
- name: "(OpenBSD) Install NGINX"
@@ -40,23 +40,23 @@
4040
build: no
4141
state: "{{ nginx_state }}"
4242
when: nginx_bsd_install_packages | bool
43-
notify: "(Handler) Start NGINX"
43+
notify: "(Handler) Run NGINX"
4444

4545
- name: "(OpenBSD) Install NGINX port"
4646
openbsd_pkg:
4747
name: "nginx{{ nginx_version | default('') }}"
4848
build: yes
4949
state: "{{ nginx_state }}"
5050
when: not nginx_bsd_install_packages | bool
51-
notify: "(Handler) Start NGINX"
51+
notify: "(Handler) Run NGINX"
5252
when: ansible_facts['system'] == "OpenBSD"
5353

5454
- name: "(NetBSD) Install NGINX"
5555
block:
5656
- name: "NetBSD) Install NGINX package"
5757
command: "pkg_add www/nginx{{ nginx_version | default('') }}"
5858
when: nginx_bsd_install_packages | bool
59-
notify: "(Handler) Start NGINX"
59+
notify: "(Handler) Run NGINX"
6060

6161
- name: "(NetBSD) Install NGINX port"
6262
fail:
@@ -69,7 +69,7 @@
6969
- name: "Install NGINX package"
7070
command: "pkg install www/nginx{{ nginx_version | default('') }}"
7171
when: nginx_bsd_install_packages | bool
72-
notify: "(Handler) Start NGINX"
72+
notify: "(Handler) Run NGINX"
7373

7474
- name: "Install NGINX port"
7575
fail:

tasks/opensource/install-debian.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
apt:
1212
name: "nginx{{ nginx_version | default('') }}"
1313
state: "{{ nginx_state }}"
14-
notify: "(Handler) Start NGINX"
14+
notify: "(Handler) Run NGINX"

tasks/opensource/install-oss.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
name: "nginx{{ nginx_version | default('') }}"
2626
state: "{{ nginx_state }}"
2727
when: nginx_install_from == "os_repository"
28-
notify: "(Handler) Start NGINX"
28+
notify: "(Handler) Run NGINX"
2929
when: ansible_facts['system'] | lower is not search('bsd')
3030

3131
- name: "Install NGINX in Unix systems"

tasks/opensource/install-redhat.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
disablerepo: "*"
3131
enablerepo: "nginx"
3232
update_cache: yes
33-
notify: "(Handler) Start NGINX"
33+
notify: "(Handler) Run NGINX"

0 commit comments

Comments
 (0)