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:
* 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.
* You can now specify an `nginx_repository` for NGINX Plus too.
* Moved "constant" variables to `vars/main.yml`.

View File

@ -1,28 +1,29 @@
---
- name: "(Handler) Check NGINX"
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:
daemon_reload: yes
notify: "(Handler) Start NGINX"
- name: "(Handler) Run NGINX"
block:
- name: "(Handler) Start NGINX"
- name: "(Handler) Start/Reload NGINX"
service:
name: nginx
state: started
state: reloaded
enabled: yes
notify: "(Handler) Check NGINX"
- name: "(Handler) Reload NGINX"
command: "nginx -s reload"
changed_when: false
when:
- nginx_start | bool
- not ansible_check_mode | bool
listen: "(Handler) Run NGINX"
- name: "(Handler) Start NGINX Amplify agent"
service:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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