Skip to content

Commit d382f7b

Browse files
authored
Merge pull request #13703 from jan-cerny/ansible_check_mode
Prevent fails in check mode
2 parents c6fe6ea + 1f9312a commit d382f7b

12 files changed

Lines changed: 76 additions & 13 deletions

File tree

  • linux_os/guide
    • services
      • fapolicyd/fapolicy_default_deny/ansible
      • ssh/ssh_server/firewalld_sshd_port_enabled/ansible
    • system
      • accounts/accounts-pam/set_password_hashing_algorithm
        • set_password_hashing_algorithm_passwordauth/ansible
        • set_password_hashing_algorithm_systemauth/ansible
      • logging/log_rotation/ensure_logrotate_activated/ansible
      • network/network-firewalld/ruleset_modifications
        • firewalld_loopback_traffic_restricted/ansible
        • firewalld_loopback_traffic_trusted/ansible
      • software
        • integrity/software-integrity/aide
        • updating/ensure_redhat_gpgkey_installed/ansible
  • shared

linux_os/guide/services/fapolicyd/fapolicy_default_deny/ansible/shared.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# complexity = low
55
# disruption = low
66

7+
- name: "{{{ rule_title }}} - Gather the package facts"
8+
ansible.builtin.package_facts:
9+
manager: auto
10+
711
- name: {{{ rule_title }}} - Ensure a Final Rule Denying Everything
812
ansible.builtin.copy:
913
content: |
@@ -15,6 +19,8 @@
1519
owner: root
1620
group: fapolicyd
1721
mode: '0644'
22+
when:
23+
- '"fapolicyd" in ansible_facts.packages'
1824
register: result_fapolicyd_final_rule
1925

2026
- name: {{{ rule_title }}} - Ensure fapolicyd is Not Permissive
@@ -23,11 +29,14 @@
2329
regexp: '^(permissive\s*=).*$'
2430
line: '\1 0'
2531
backrefs: true
32+
when:
33+
- '"fapolicyd" in ansible_facts.packages'
2634
register: result_fapolicyd_enforced
2735

2836
- name: "{{{ rule_title }}} - Restart fapolicyd If Permissive Mode or Final Rule is Changed"
2937
ansible.builtin.service:
3038
name: fapolicyd
3139
state: restarted
3240
when:
41+
- '"fapolicyd" in ansible_facts.packages'
3342
- result_fapolicyd_final_rule is changed or result_fapolicyd_enforced is changed

linux_os/guide/services/ssh/ssh_server/firewalld_sshd_port_enabled/ansible/shared.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
- name: '{{{ rule_title }}} - Informative message based on services states'
8080
ansible.builtin.assert:
8181
that:
82-
- ansible_facts.services['firewalld.service'].state == 'running'
83-
- ansible_facts.services['NetworkManager.service'].state == 'running'
82+
- ansible_check_mode or ansible_facts.services['firewalld.service'].state == 'running'
83+
- ansible_check_mode or ansible_facts.services['NetworkManager.service'].state == 'running'
8484
fail_msg:
8585
- firewalld and NetworkManager services are not active. Remediation aborted!
8686
- This remediation could not be applied because it depends on firewalld and NetworkManager services running.

linux_os/guide/system/accounts/accounts-pam/set_password_hashing_algorithm/set_password_hashing_algorithm_passwordauth/ansible/shared.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@
1818
block:
1919
{{{ ansible_ensure_pam_facts_and_authselect_profile(pam_file, rule_title=rule_title) | indent(4) }}}
2020

21-
- name: '{{{ rule_title }}} - Ensure That Only the Correct Hashing Algorithm Option For pam_unix.so Is Used in {{{ pam_file }}}'
21+
- name: '{{{ rule_title }}} - Check if "{{ pam_file_path }}" File is Present'
22+
ansible.builtin.stat:
23+
path: "{{ pam_file_path }}"
24+
register: pam_file_path_present
25+
26+
- name: '{{{ rule_title }}} - Ensure That Only the Correct Hashing Algorithm Option For pam_unix.so Is Used in {{ pam_file_path }}'
2227
ansible.builtin.replace:
2328
dest: "{{ pam_file_path }}"
2429
regexp: (^\s*password.*pam_unix\.so.*)\b{{ item }}\b\s*(.*)
2530
replace: '\1\2'
2631
when:
27-
item != var_password_hashing_algorithm_pam
32+
- item != var_password_hashing_algorithm_pam
33+
- pam_file_path_present.stat.exists
2834
loop:
2935
- 'sha512'
3036
- 'yescrypt'

linux_os/guide/system/accounts/accounts-pam/set_password_hashing_algorithm/set_password_hashing_algorithm_systemauth/ansible/shared.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@
2424
block:
2525
{{{ ansible_ensure_pam_facts_and_authselect_profile(pam_file, rule_title=rule_title) | indent(4) }}}
2626

27-
- name: '{{{ rule_title }}} - Ensure That Only the Correct Hashing Algorithm Option For pam_unix.so Is Used in {{{ pam_file }}}'
27+
- name: '{{{ rule_title }}} - Check if "{{ pam_file_path }}" File is Present'
28+
ansible.builtin.stat:
29+
path: "{{ pam_file_path }}"
30+
register: pam_file_path_present
31+
32+
- name: '{{{ rule_title }}} - Ensure That Only the Correct Hashing Algorithm Option For pam_unix.so Is Used in {{ pam_file_path }}'
2833
ansible.builtin.replace:
2934
dest: "{{ pam_file_path }}"
3035
regexp: (^\s*password.*pam_unix\.so.*)\b{{ item }}\b\s*(.*)
3136
replace: '\1\2'
3237
when:
33-
item != var_password_hashing_algorithm_pam
38+
- item != var_password_hashing_algorithm_pam
39+
- pam_file_path_present.stat.exists
3440
loop:
3541
- 'sha512'
3642
- 'yescrypt'

linux_os/guide/system/logging/log_rotation/ensure_logrotate_activated/ansible/shared.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@
3939
path: "/etc/cron.daily/logrotate"
4040
line: '/usr/sbin/logrotate /etc/logrotate.conf'
4141
regexp: '^[\s]*/usr/sbin/logrotate[\s\S]*/etc/logrotate.conf$'
42+
create: yes
4243
{{% endif %}}

linux_os/guide/system/network/network-firewalld/ruleset_modifications/firewalld_loopback_traffic_restricted/ansible/shared.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
- name: '{{{ rule_title }}} - Informative Message Based on Service State'
4444
ansible.builtin.assert:
4545
that:
46-
- ansible_facts.services['firewalld.service'].state == 'running'
46+
- ansible_check_mode or ansible_facts.services['firewalld.service'].state == 'running'
4747
fail_msg:
4848
- firewalld service is not active. Remediation aborted!
4949
- This remediation could not be applied because it depends on firewalld service running.

linux_os/guide/system/network/network-firewalld/ruleset_modifications/firewalld_loopback_traffic_trusted/ansible/shared.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
- name: '{{{ rule_title }}} - Informative Message Based on Service State'
3737
ansible.builtin.assert:
3838
that:
39-
- ansible_facts.services['firewalld.service'].state == 'running'
39+
- ansible_check_mode or ansible_facts.services['firewalld.service'].state == 'running'
4040
fail_msg:
4141
- firewalld service is not active. Remediation aborted!
4242
- This remediation could not be applied because it depends on firewalld service running.

linux_os/guide/system/software/integrity/software-integrity/aide/aide_check_audit_tools/ansible/shared.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
with_items:
1818
- aide
1919

20+
- name: "{{{ rule_title }}} - Gather the package facts"
21+
ansible.builtin.package_facts:
22+
manager: auto
2023

2124
- name: Set audit_tools fact
2225
set_fact:
@@ -39,11 +42,16 @@
3942
path: {{{ aide_conf_path }}}
4043
regexp: ^{{ item }}\s
4144
line: "{{ item }} {{{ aide_string() }}}"
45+
create: true
4246
with_items: "{{ audit_tools }}"
43-
47+
when:
48+
- '"aide" in ansible_facts.packages'
4449

4550
- name: Configure AIDE to properly protect audit tools
4651
lineinfile:
4752
path: {{{ aide_conf_path }}}
4853
line: "{{ item }} {{{ aide_string() }}}"
54+
create: true
4955
with_items: "{{ audit_tools }}"
56+
when:
57+
- '"aide" in ansible_facts.packages'

linux_os/guide/system/software/integrity/software-integrity/aide/aide_use_fips_hashes/ansible/shared.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,23 @@
2222
- gost
2323
- crc32
2424

25+
- name: "{{{ rule_title }}} - Gather the package facts"
26+
ansible.builtin.package_facts:
27+
manager: auto
28+
2529
- name: "{{{ rule_title }}} - Remove forbidden hashes"
2630
ansible.builtin.replace:
2731
path: "{{ aide_conf }}"
2832
regexp: '(^\s*[A-Z][A-Za-z_]*\s*=.*?)({{ item }}\+|\+?{{ item }})(.*)'
2933
replace: '\1\3'
34+
when:
35+
- '"aide" in ansible_facts.packages'
3036
loop: "{{ forbidden_hashes }}"
3137

3238
- name: "{{{ rule_title }}} - Set sha512"
3339
ansible.builtin.replace:
3440
path: "{{ aide_conf }}"
3541
regexp: '(^\s*[A-Z][A-Za-z_]*\s*=)((?:(?!\+?sha512).)*)\s*$'
3642
replace: '\1\2+sha512'
43+
when:
44+
- '"aide" in ansible_facts.packages'

linux_os/guide/system/software/updating/ensure_redhat_gpgkey_installed/ansible/shared.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
{{%- endif %}}
2121
changed_when: False
2222
register: gpg_fingerprints
23+
failed_when: False
2324
check_mode: no
2425

2526
- name: Set Fact - Installed GPG Fingerprints

0 commit comments

Comments
 (0)