Skip to content

Commit ab76f7a

Browse files
authored
Fix errors when using Ansible's check mode (#339)
1 parent a4b40b2 commit ab76f7a

13 files changed

+30
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ BUG FIXES:
1212

1313
* Prevent TravisCI from trying to build (and failing) NGINX Plus images on external PRs.
1414
* Fix naming for SELinux facts dict.
15+
* Role now runs correctly when using Ansible's check mode.
1516

1617
## 0.17.2 (September 24, 2020)
1718

handlers/main.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@
1515

1616
- name: (Handler) Check NGINX
1717
command: nginx -t
18-
register: config
18+
register: config_check
1919
ignore_errors: yes
20+
check_mode: no
2021
changed_when: false
2122
listen: (Handler) Run NGINX
2223

2324
- name: (Handler) Print NGINX error if syntax check fails
2425
debug:
25-
var: config.stderr_lines
26-
failed_when: config.rc != 0
27-
when: config.rc != 0
26+
var: config_check.stderr_lines
27+
failed_when: config_check.rc != 0
28+
when:
29+
- config_check.stderr_lines is defined
30+
- config_check.rc != 0
2831
listen: (Handler) Run NGINX
2932

3033
- name: (Handler) Start NGINX Amplify agent

tasks/config/debug-output.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
---
22
- name: Register NGINX config
33
command: nginx -T
4+
ignore_errors: "{{ ansible_check_mode }}"
5+
check_mode: no
46
changed_when: false
5-
register: config
7+
register: config_full
68

79
- name: Print NGINX config
810
debug:
9-
var: config.stdout_lines
11+
var: config_full.stdout_lines
12+
when: config_full.stdout_lines is defined

tasks/opensource/install-alpine.yml

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

tasks/opensource/install-bsd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@
6666

6767
- name: (DragonFlyBSD/HardenedBSD) Install NGINX
6868
block:
69-
- name: Install NGINX package
69+
- name: (DragonFlyBSD/HardenedBSD) Install NGINX package
7070
command: "pkg install www/nginx{{ nginx_version | default('') }}"
7171
when: nginx_bsd_install_packages | bool
7272
notify: (Handler) Run NGINX
7373

74-
- name: Install NGINX port
74+
- name: (DragonFlyBSD/HardenedBSD) Install NGINX port
7575
fail:
7676
msg: "{{ ansible_facts['system'] }} Install NGINX port not implemented."
7777
when: not nginx_bsd_install_packages | bool

tasks/opensource/install-debian.yml

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

tasks/opensource/install-redhat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@
3030
disablerepo: "*"
3131
enablerepo: nginx
3232
update_cache: yes
33+
ignore_errors: "{{ ansible_check_mode }}"
3334
notify: (Handler) Run NGINX

tasks/opensource/install-source.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
when:
158158
- not pcre_result.stat.exists | bool
159159
- not nginx_install_source_pcre | bool
160+
- not ansible_check_mode | bool
160161

161162
- name: (Centos/RHEL) Install ZLib dependency from package
162163
yum:
@@ -216,6 +217,7 @@
216217
when:
217218
- not zlib_result.stat.exists | bool
218219
- not nginx_install_source_zlib | bool
220+
- not ansible_check_mode | bool
219221

220222
- name: (CentOS/RHEL) Install OpenSSL dependency from package
221223
yum:
@@ -275,6 +277,7 @@
275277
when:
276278
- not openssl_result.stat.exists | bool
277279
- not nginx_install_source_openssl | bool
280+
- not ansible_check_mode | bool
278281

279282
- name: Get NGINX version
280283
block:
@@ -284,6 +287,7 @@
284287
return_content: yes
285288
validate_certs: "{{ (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] is version('6', '=='))
286289
| ternary('no', 'yes') }}"
290+
check_mode: no
287291
register: nginx_versions
288292

289293
- name: Set NGINX mainline version
@@ -430,7 +434,9 @@
430434
command: rc-update add nginx default
431435
when: ansible_facts['service_mgr'] == "openrc"
432436
notify: (Handler) Run NGINX
433-
when: not nginx_result.stat.exists
437+
when:
438+
- not nginx_result.stat.exists | bool
439+
- not ansible_check_mode | bool
434440

435441
- name: Cleanup downloads
436442
file:

tasks/opensource/install-suse.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
state: "{{ nginx_state }}"
1111
disable_recommends: no
1212
update_cache: yes
13+
ignore_errors: "{{ ansible_check_mode }}"
1314
notify: (Handler) Run NGINX

tasks/plus/install-alpine.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
name: "nginx-plus{{ nginx_version | default('') }}"
1212
repository: "{{ repository }}"
1313
state: "{{ nginx_state }}"
14+
ignore_errors: "{{ ansible_check_mode }}"
1415
notify: (Handler) Run NGINX

tasks/plus/install-debian.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
name: "nginx-plus{{ nginx_version | default('') }}"
2525
state: "{{ nginx_state }}"
2626
update_cache: yes
27+
ignore_errors: "{{ ansible_check_mode }}"
2728
notify: (Handler) Run NGINX

tasks/plus/install-redhat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
disablerepo: "*"
1919
enablerepo: "nginx-plus"
2020
update_cache: yes
21+
ignore_errors: "{{ ansible_check_mode }}"
2122
notify: (Handler) Run NGINX

tasks/plus/install-suse.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
name: "nginx-plus{{ nginx_version | default('') }}"
1717
state: "{{ nginx_state }}"
1818
update_cache: yes
19+
ignore_errors: "{{ ansible_check_mode }}"
1920
notify: (Handler) Run NGINX

0 commit comments

Comments
 (0)