Refactor handlers (#321)

This commit is contained in:
Alessandro Fael Garcia 2020-09-17 17:00:27 +02:00 committed by GitHub
parent 28d1da5e0a
commit 903693e67f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 53 additions and 51 deletions

View File

@ -20,6 +20,7 @@ FEATURES:
ENHANCEMENTS: ENHANCEMENTS:
* Added handlers to check for NGINX syntax validity and fail if any errors are detected.
* Major backend refactoring to reduce the number of files and tasks. * Major backend refactoring to reduce the number of files and tasks.
* You can now specify an `nginx_repository` for NGINX Plus too. * You can now specify an `nginx_repository` for NGINX Plus too.
* Moved "constant" variables to `vars/main.yml`. * Moved "constant" variables to `vars/main.yml`.

View File

@ -1,28 +1,29 @@
--- ---
- name: "(Handler) Check NGINX" - name: "(Handler) Check NGINX"
command: "nginx -t" command: "nginx -t"
changed_when: false register: config
ignore_errors: yes
listen: "(Handler) Run NGINX"
- name: "(Handler) Systemd Daemon-Reload" - name: "(Handler) Print NGINX error if syntax check fails"
fail:
msg: "{{ config.stderr }}"
when: config.rc != 0
listen: "(Handler) Run NGINX"
- name: "(Handler) Systemd daemon-reload"
systemd: systemd:
daemon_reload: yes daemon_reload: yes
notify: "(Handler) Start NGINX"
- name: "(Handler) Run NGINX" - name: "(Handler) Start/Reload NGINX"
block:
- name: "(Handler) Start NGINX"
service: service:
name: nginx name: nginx
state: started state: reloaded
enabled: yes enabled: yes
notify: "(Handler) Check NGINX"
- name: "(Handler) Reload NGINX"
command: "nginx -s reload"
changed_when: false
when: when:
- nginx_start | bool - nginx_start | bool
- not ansible_check_mode | bool - not ansible_check_mode | bool
listen: "(Handler) Run NGINX"
- name: "(Handler) Start NGINX Amplify agent" - name: "(Handler) Start NGINX Amplify agent"
service: service:

View File

@ -20,7 +20,7 @@
when: when:
- not nginx_service_custom | bool - not nginx_service_custom | bool
- not nginx_service_clean | bool - not nginx_service_clean | bool
notify: "(Handler) Systemd Daemon-Reload" notify: "(Handler) Systemd daemon-reload"
- name: "Customize override for NGINX systemd service" - name: "Customize override for NGINX systemd service"
copy: copy:
@ -32,14 +32,14 @@
when: when:
- nginx_service_custom | bool - nginx_service_custom | bool
- not nginx_service_clean | bool - not nginx_service_clean | bool
notify: "(Handler) Systemd Daemon-Reload" notify: "(Handler) Systemd daemon-reload"
- name: "Remove override for NGINX systemd service" - name: "Remove override for NGINX systemd service"
file: file:
path: "{{ nginx_service_overridepath }}" path: "{{ nginx_service_overridepath }}"
state: absent state: absent
when: nginx_service_clean | bool when: nginx_service_clean | bool
notify: "(Handler) Systemd Daemon-Reload" notify: "(Handler) Systemd daemon-reload"
- name: "Modify systemd" - name: "Modify systemd"
debug: debug:

View File

@ -35,7 +35,7 @@
backup: yes backup: yes
mode: 0644 mode: 0644
when: nginx_main_template_enable | bool when: nginx_main_template_enable | bool
notify: "(Handler) Reload NGINX" notify: "(Handler) Run NGINX"
- name: "(DEPRECATED) Ensure NGINX HTTP Directory Exists" - name: "(DEPRECATED) Ensure NGINX HTTP Directory Exists"
file: file:
@ -65,7 +65,7 @@
mode: 0644 mode: 0644
with_dict: "{{ nginx_http_template }}" with_dict: "{{ nginx_http_template }}"
when: nginx_http_template_enable | bool when: nginx_http_template_enable | bool
notify: "(Handler) Reload NGINX" notify: "(Handler) Run NGINX"
- name: "(DEPRECATED) Dynamically Generate NGINX Stub Status Configuration File" - name: "(DEPRECATED) Dynamically Generate NGINX Stub Status Configuration File"
template: template:
@ -74,7 +74,7 @@
backup: yes backup: yes
mode: 0644 mode: 0644
when: nginx_status_enable | bool when: nginx_status_enable | bool
notify: "(Handler) Reload NGINX" notify: "(Handler) Run NGINX"
- name: "(DEPRECATED) Dynamically Generate NGINX API Configuration File" - name: "(DEPRECATED) Dynamically Generate NGINX API Configuration File"
template: template:
@ -83,7 +83,7 @@
backup: yes backup: yes
mode: 0644 mode: 0644
when: nginx_rest_api_enable | bool when: nginx_rest_api_enable | bool
notify: "(Handler) Reload NGINX" notify: "(Handler) Run NGINX"
- name: "(DEPRECATED) Ensure NGINX Stream Directory Exists" - name: "(DEPRECATED) Ensure NGINX Stream Directory Exists"
file: file:
@ -101,4 +101,4 @@
mode: 0644 mode: 0644
with_dict: "{{ nginx_stream_template }}" with_dict: "{{ nginx_stream_template }}"
when: nginx_stream_template_enable | bool when: nginx_stream_template_enable | bool
notify: "(Handler) Reload NGINX" notify: "(Handler) Run NGINX"

View File

@ -19,7 +19,7 @@
mode: 0644 mode: 0644
with_fileglob: "{{ nginx_html_upload_src }}" with_fileglob: "{{ nginx_html_upload_src }}"
when: nginx_html_upload_enable | bool when: nginx_html_upload_enable | bool
notify: "(Handler) Reload NGINX" notify: "(Handler) Run NGINX"
- name: "(DEPRECATED) Ensure NGINX Main Directory Exists" - name: "(DEPRECATED) Ensure NGINX Main Directory Exists"
file: file:
@ -35,7 +35,7 @@
backup: yes backup: yes
mode: 0644 mode: 0644
when: nginx_main_upload_enable | bool when: nginx_main_upload_enable | bool
notify: "(Handler) Reload NGINX" notify: "(Handler) Run NGINX"
- name: "(DEPRECATED) Ensure NGINX HTTP Directory Exists" - name: "(DEPRECATED) Ensure NGINX HTTP Directory Exists"
file: file:
@ -52,7 +52,7 @@
mode: 0644 mode: 0644
with_fileglob: "{{ nginx_http_upload_src }}" with_fileglob: "{{ nginx_http_upload_src }}"
when: nginx_http_upload_enable | bool when: nginx_http_upload_enable | bool
notify: "(Handler) Reload NGINX" notify: "(Handler) Run NGINX"
- name: "(DEPRECATED) Ensure NGINX Stream Directory Exists" - name: "(DEPRECATED) Ensure NGINX Stream Directory Exists"
file: file:
@ -69,7 +69,7 @@
mode: 0644 mode: 0644
with_fileglob: "{{ nginx_stream_upload_src }}" with_fileglob: "{{ nginx_stream_upload_src }}"
when: nginx_stream_upload_enable | bool when: nginx_stream_upload_enable | bool
notify: "(Handler) Reload NGINX" notify: "(Handler) Run NGINX"
- name: "(DEPRECATED) Ensure SSL Certificate Directory Exists" - name: "(DEPRECATED) Ensure SSL Certificate Directory Exists"
file: file:

View File

@ -11,4 +11,4 @@
repository: "{{ repository }}" repository: "{{ repository }}"
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
update_cache: yes update_cache: yes
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"

View File

@ -21,7 +21,7 @@
name: "www/nginx{{ nginx_version | default('') }}" name: "www/nginx{{ nginx_version | default('') }}"
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
when: nginx_bsd_install_packages | bool when: nginx_bsd_install_packages | bool
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
- name: "(FreeBSD) Install NGINX port" - name: "(FreeBSD) Install NGINX port"
portinstall: portinstall:
@ -29,7 +29,7 @@
use_packages: "{{ nginx_bsd_portinstall_use_packages | default(omit) }}" use_packages: "{{ nginx_bsd_portinstall_use_packages | default(omit) }}"
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
when: not nginx_bsd_install_packages | bool when: not nginx_bsd_install_packages | bool
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
when: ansible_facts['system'] == "FreeBSD" when: ansible_facts['system'] == "FreeBSD"
- name: "(OpenBSD) Install NGINX" - name: "(OpenBSD) Install NGINX"
@ -40,7 +40,7 @@
build: no build: no
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
when: nginx_bsd_install_packages | bool when: nginx_bsd_install_packages | bool
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
- name: "(OpenBSD) Install NGINX port" - name: "(OpenBSD) Install NGINX port"
openbsd_pkg: openbsd_pkg:
@ -48,7 +48,7 @@
build: yes build: yes
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
when: not nginx_bsd_install_packages | bool when: not nginx_bsd_install_packages | bool
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
when: ansible_facts['system'] == "OpenBSD" when: ansible_facts['system'] == "OpenBSD"
- name: "(NetBSD) Install NGINX" - name: "(NetBSD) Install NGINX"
@ -56,7 +56,7 @@
- name: "NetBSD) Install NGINX package" - name: "NetBSD) Install NGINX package"
command: "pkg_add www/nginx{{ nginx_version | default('') }}" command: "pkg_add www/nginx{{ nginx_version | default('') }}"
when: nginx_bsd_install_packages | bool when: nginx_bsd_install_packages | bool
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
- name: "(NetBSD) Install NGINX port" - name: "(NetBSD) Install NGINX port"
fail: fail:
@ -69,7 +69,7 @@
- name: "Install NGINX package" - name: "Install NGINX package"
command: "pkg install www/nginx{{ nginx_version | default('') }}" command: "pkg install www/nginx{{ nginx_version | default('') }}"
when: nginx_bsd_install_packages | bool when: nginx_bsd_install_packages | bool
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
- name: "Install NGINX port" - name: "Install NGINX port"
fail: fail:

View File

@ -11,4 +11,4 @@
apt: apt:
name: "nginx{{ nginx_version | default('') }}" name: "nginx{{ nginx_version | default('') }}"
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"

View File

@ -25,7 +25,7 @@
name: "nginx{{ nginx_version | default('') }}" name: "nginx{{ nginx_version | default('') }}"
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
when: nginx_install_from == "os_repository" when: nginx_install_from == "os_repository"
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
when: ansible_facts['system'] | lower is not search('bsd') when: ansible_facts['system'] | lower is not search('bsd')
- name: "Install NGINX in Unix systems" - name: "Install NGINX in Unix systems"

View File

@ -30,4 +30,4 @@
disablerepo: "*" disablerepo: "*"
enablerepo: "nginx" enablerepo: "nginx"
update_cache: yes update_cache: yes
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"

View File

@ -378,7 +378,7 @@
state: restarted state: restarted
enabled: yes enabled: yes
when: ansible_facts['service_mgr'] == "systemd" when: ansible_facts['service_mgr'] == "systemd"
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
- name: "Upload upstart NGINX service file" - name: "Upload upstart NGINX service file"
copy: copy:
@ -405,7 +405,7 @@
- name: "Start Upstart NGINX service reload" - name: "Start Upstart NGINX service reload"
command: "nginx" command: "nginx"
when: ansible_facts['service_mgr'] == "upstart" when: ansible_facts['service_mgr'] == "upstart"
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
- name: "Upload SysVinit NGINX service file" - name: "Upload SysVinit NGINX service file"
copy: copy:
@ -415,7 +415,7 @@
group: root group: root
mode: 0755 mode: 0755
when: ansible_facts['service_mgr'] == "sysvinit" when: ansible_facts['service_mgr'] == "sysvinit"
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
- name: "Upload OpenRC NGINX service file" - name: "Upload OpenRC NGINX service file"
copy: copy:
@ -429,7 +429,7 @@
- name: "Enable OpenRC NGINX service" - name: "Enable OpenRC NGINX service"
command: rc-update add nginx default command: rc-update add nginx default
when: ansible_facts['service_mgr'] == "openrc" when: ansible_facts['service_mgr'] == "openrc"
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"
when: not nginx_result.stat.exists when: not nginx_result.stat.exists
- name: "Cleanup downloads" - name: "Cleanup downloads"

View File

@ -10,4 +10,4 @@
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
disable_recommends: no disable_recommends: no
update_cache: yes update_cache: yes
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"

View File

@ -11,4 +11,4 @@
name: "nginx-plus{{ nginx_version | default('') }}" name: "nginx-plus{{ nginx_version | default('') }}"
repository: "{{ repository }}" repository: "{{ repository }}"
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"

View File

@ -23,4 +23,4 @@
apt: apt:
name: "nginx-plus{{ nginx_version | default('') }}" name: "nginx-plus{{ nginx_version | default('') }}"
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"

View File

@ -25,4 +25,4 @@
pkgng: pkgng:
name: "nginx-plus{{ nginx_version | default('') }}" name: "nginx-plus{{ nginx_version | default('') }}"
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"

View File

@ -18,4 +18,4 @@
disablerepo: "*" disablerepo: "*"
enablerepo: "nginx-plus" enablerepo: "nginx-plus"
update_cache: yes update_cache: yes
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"

View File

@ -16,4 +16,4 @@
name: "nginx-plus{{ nginx_version | default('') }}" name: "nginx-plus{{ nginx_version | default('') }}"
state: "{{ nginx_state }}" state: "{{ nginx_state }}"
update_cache: yes update_cache: yes
notify: "(Handler) Start NGINX" notify: "(Handler) Run NGINX"

View File

@ -19,8 +19,8 @@
decrypt: yes decrypt: yes
mode: 0444 mode: 0444
loop: loop:
- "{{ nginx_license.certificate }}" - "{{ nginx_license['certificate'] }}"
- "{{ nginx_license.key }}" - "{{ nginx_license['key'] }}"
when: ansible_facts['os_family'] != "Alpine" when: ansible_facts['os_family'] != "Alpine"
- name: "(Alpine Linux) Set up NGINX Plus license" - name: "(Alpine Linux) Set up NGINX Plus license"
@ -33,14 +33,14 @@
- name: "(Alpine Linux) Copy NGINX Plus key" - name: "(Alpine Linux) Copy NGINX Plus key"
copy: copy:
src: "{{ nginx_license.key }}" src: "{{ nginx_license['key'] }}"
dest: /etc/apk/cert.key dest: /etc/apk/cert.key
decrypt: yes decrypt: yes
mode: 0444 mode: 0444
- name: "(Alpine Linux) Copy NGINX Plus certificate" - name: "(Alpine Linux) Copy NGINX Plus certificate"
copy: copy:
src: "{{ nginx_license.certificate }}" src: "{{ nginx_license['certificate'] }}"
dest: /etc/apk/cert.pem dest: /etc/apk/cert.pem
decrypt: yes decrypt: yes
mode: 0444 mode: 0444