diff --git a/CHANGELOG.md b/CHANGELOG.md index c8a8297..dafa978 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ BUG FIXES: * Prevent TravisCI from trying to build (and failing) NGINX Plus images on external PRs. * Fix naming for SELinux facts dict. +* Role now runs correctly when using Ansible's check mode. ## 0.17.2 (September 24, 2020) diff --git a/handlers/main.yml b/handlers/main.yml index 40cba59..7ee5976 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -15,16 +15,19 @@ - name: (Handler) Check NGINX command: nginx -t - register: config + register: config_check ignore_errors: yes + check_mode: no changed_when: false listen: (Handler) Run NGINX - name: (Handler) Print NGINX error if syntax check fails debug: - var: config.stderr_lines - failed_when: config.rc != 0 - when: config.rc != 0 + var: config_check.stderr_lines + failed_when: config_check.rc != 0 + when: + - config_check.stderr_lines is defined + - config_check.rc != 0 listen: (Handler) Run NGINX - name: (Handler) Start NGINX Amplify agent diff --git a/tasks/config/debug-output.yml b/tasks/config/debug-output.yml index bde66f7..0ea0a41 100644 --- a/tasks/config/debug-output.yml +++ b/tasks/config/debug-output.yml @@ -1,9 +1,12 @@ --- - name: Register NGINX config command: nginx -T + ignore_errors: "{{ ansible_check_mode }}" + check_mode: no changed_when: false - register: config + register: config_full - name: Print NGINX config debug: - var: config.stdout_lines + var: config_full.stdout_lines + when: config_full.stdout_lines is defined diff --git a/tasks/opensource/install-alpine.yml b/tasks/opensource/install-alpine.yml index 22addcc..24b7d96 100644 --- a/tasks/opensource/install-alpine.yml +++ b/tasks/opensource/install-alpine.yml @@ -11,4 +11,5 @@ repository: "{{ repository }}" state: "{{ nginx_state }}" update_cache: yes + ignore_errors: "{{ ansible_check_mode }}" notify: (Handler) Run NGINX diff --git a/tasks/opensource/install-bsd.yml b/tasks/opensource/install-bsd.yml index a81d43f..de78d65 100644 --- a/tasks/opensource/install-bsd.yml +++ b/tasks/opensource/install-bsd.yml @@ -66,12 +66,12 @@ - name: (DragonFlyBSD/HardenedBSD) Install NGINX block: - - name: Install NGINX package + - name: (DragonFlyBSD/HardenedBSD) Install NGINX package command: "pkg install www/nginx{{ nginx_version | default('') }}" when: nginx_bsd_install_packages | bool notify: (Handler) Run NGINX - - name: Install NGINX port + - name: (DragonFlyBSD/HardenedBSD) Install NGINX port fail: msg: "{{ ansible_facts['system'] }} Install NGINX port not implemented." when: not nginx_bsd_install_packages | bool diff --git a/tasks/opensource/install-debian.yml b/tasks/opensource/install-debian.yml index 2d188e4..7bde851 100644 --- a/tasks/opensource/install-debian.yml +++ b/tasks/opensource/install-debian.yml @@ -11,4 +11,5 @@ apt: name: "nginx{{ nginx_version | default('') }}" state: "{{ nginx_state }}" + ignore_errors: "{{ ansible_check_mode }}" notify: (Handler) Run NGINX diff --git a/tasks/opensource/install-redhat.yml b/tasks/opensource/install-redhat.yml index db47f4d..e83c1b8 100644 --- a/tasks/opensource/install-redhat.yml +++ b/tasks/opensource/install-redhat.yml @@ -30,4 +30,5 @@ disablerepo: "*" enablerepo: nginx update_cache: yes + ignore_errors: "{{ ansible_check_mode }}" notify: (Handler) Run NGINX diff --git a/tasks/opensource/install-source.yml b/tasks/opensource/install-source.yml index b6db72c..af2cf8d 100644 --- a/tasks/opensource/install-source.yml +++ b/tasks/opensource/install-source.yml @@ -157,6 +157,7 @@ when: - not pcre_result.stat.exists | bool - not nginx_install_source_pcre | bool + - not ansible_check_mode | bool - name: (Centos/RHEL) Install ZLib dependency from package yum: @@ -216,6 +217,7 @@ when: - not zlib_result.stat.exists | bool - not nginx_install_source_zlib | bool + - not ansible_check_mode | bool - name: (CentOS/RHEL) Install OpenSSL dependency from package yum: @@ -275,6 +277,7 @@ when: - not openssl_result.stat.exists | bool - not nginx_install_source_openssl | bool + - not ansible_check_mode | bool - name: Get NGINX version block: @@ -284,6 +287,7 @@ return_content: yes validate_certs: "{{ (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('6', '==')) | ternary('no', 'yes') }}" + check_mode: no register: nginx_versions - name: Set NGINX mainline version @@ -430,7 +434,9 @@ command: rc-update add nginx default when: ansible_facts['service_mgr'] == "openrc" notify: (Handler) Run NGINX - when: not nginx_result.stat.exists + when: + - not nginx_result.stat.exists | bool + - not ansible_check_mode | bool - name: Cleanup downloads file: diff --git a/tasks/opensource/install-suse.yml b/tasks/opensource/install-suse.yml index 3579fc7..ed405cc 100644 --- a/tasks/opensource/install-suse.yml +++ b/tasks/opensource/install-suse.yml @@ -10,4 +10,5 @@ state: "{{ nginx_state }}" disable_recommends: no update_cache: yes + ignore_errors: "{{ ansible_check_mode }}" notify: (Handler) Run NGINX diff --git a/tasks/plus/install-alpine.yml b/tasks/plus/install-alpine.yml index dc2f1ad..28d2573 100644 --- a/tasks/plus/install-alpine.yml +++ b/tasks/plus/install-alpine.yml @@ -11,4 +11,5 @@ name: "nginx-plus{{ nginx_version | default('') }}" repository: "{{ repository }}" state: "{{ nginx_state }}" + ignore_errors: "{{ ansible_check_mode }}" notify: (Handler) Run NGINX diff --git a/tasks/plus/install-debian.yml b/tasks/plus/install-debian.yml index 3406bef..5ff346f 100644 --- a/tasks/plus/install-debian.yml +++ b/tasks/plus/install-debian.yml @@ -24,4 +24,5 @@ name: "nginx-plus{{ nginx_version | default('') }}" state: "{{ nginx_state }}" update_cache: yes + ignore_errors: "{{ ansible_check_mode }}" notify: (Handler) Run NGINX diff --git a/tasks/plus/install-redhat.yml b/tasks/plus/install-redhat.yml index 144ee2b..2a5155a 100644 --- a/tasks/plus/install-redhat.yml +++ b/tasks/plus/install-redhat.yml @@ -18,4 +18,5 @@ disablerepo: "*" enablerepo: "nginx-plus" update_cache: yes + ignore_errors: "{{ ansible_check_mode }}" notify: (Handler) Run NGINX diff --git a/tasks/plus/install-suse.yml b/tasks/plus/install-suse.yml index 7eaef49..0be7a71 100644 --- a/tasks/plus/install-suse.yml +++ b/tasks/plus/install-suse.yml @@ -16,4 +16,5 @@ name: "nginx-plus{{ nginx_version | default('') }}" state: "{{ nginx_state }}" update_cache: yes + ignore_errors: "{{ ansible_check_mode }}" notify: (Handler) Run NGINX