Skip to content

Commit

Permalink
use failed_when:false for Ansible register: checks
Browse files Browse the repository at this point in the history
Using ignore_errors leads to user-visible fatal errors
produced by ansible-playbook:

  TASK [Enable FIPS Mode - Check to See the Current Status of FIPS Mode] *********
  fatal: [192.168.122.178]: FAILED! => {"changed": false, "cmd": ["/usr/bin/fips-mode-setup", "--check"] ...

These are indistinguishable from actually terminating
fatal errors (to a log-reading script) that need to be
investigated.

Using failed_when avoids those, while still registering
the output for use by other checks, as done by many other
checks:

  $ grep -i 'failed_when: false' -r linux_os/ | wc -l
  25

Signed-off-by: Jiri Jaburek <comps@nomail.dom>
  • Loading branch information
comps committed Apr 2, 2024
1 parent 695c283 commit 40fdde4
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- name: "Test for domain group"
command: grep '^\s*\[domain\/[^]]*]' /etc/sssd/sssd.conf
register: test_grep_domain
ignore_errors: yes
failed_when: false
changed_when: False
check_mode: no

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- name: "Test for domain group"
command: grep '\s*\[domain\/[^]]*]' /etc/sssd/sssd.conf
register: test_grep_domain
ignore_errors: yes
failed_when: false
changed_when: False
check_mode: no

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- name: "Test for domain group"
command: grep '\s*\[domain\/[^]]*]' /etc/sssd/sssd.conf
register: test_grep_domain
ignore_errors: yes
failed_when: false
changed_when: False
check_mode: no

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- name: "Test for domain group"
command: grep '\s*\[domain\/[^]]*]' /etc/sssd/sssd.conf
register: test_grep_domain
ignore_errors: yes
failed_when: false
changed_when: False
check_mode: no

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
ansible.builtin.command:
cmd: semanage fcontext -a -t faillog_t "{{ var_accounts_passwords_pam_faillock_dir }}(/.*)?"
register: result_accounts_passwords_pam_faillock_dir_semanage
ignore_errors: yes
failed_when: false
changed_when:
- result_accounts_passwords_pam_faillock_dir_semanage.rc == 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- name: "{{{ rule_title }}} - Check to See the Current Status of FIPS Mode"
ansible.builtin.command: /usr/bin/fips-mode-setup --check
register: is_fips_enabled
ignore_errors: yes
failed_when: false
changed_when: false

- name: "{{{ rule_title }}} - Enable FIPS Mode"
Expand Down

0 comments on commit 40fdde4

Please sign in to comment.