Skip to content

Commit 80b5408

Browse files
authored
Merge pull request #11263 from teacup-on-rockingchair/sle15_fix_ansible_pcidss_remediations
Sle15 fix ansible pci-dss remediations in check mode
2 parents 599c8e1 + 08d6c3f commit 80b5408

5 files changed

Lines changed: 21 additions & 12 deletions

File tree

  • linux_os/guide/system
    • auditing/auditd_configure_rules
      • audit_privileged_commands/audit_rules_privileged_commands/ansible
      • file_permissions_var_log_audit/ansible
    • software/updating/ensure_gpgcheck_never_disabled/ansible
  • shared

linux_os/guide/system/auditing/auditd_configure_rules/audit_privileged_commands/audit_rules_privileged_commands/ansible/shared.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
- name: {{{ rule_title }}} - Set List of Privileged Commands Found in Eligible Mount Points
2020
ansible.builtin.set_fact:
21-
privileged_commands: "{{( result_privileged_commands_search.results | map(attribute='stdout_lines') | select() | list ) | sum(start=[]) }}"
21+
privileged_commands: "{{ privileged_commands | default([]) + item.stdout_lines }}"
22+
loop: "{{ result_privileged_commands_search.results }}"
23+
when: item is not skipped
2224

2325
- name: {{{ rule_title }}} - Privileged Commands are Present in the System
2426
block:

linux_os/guide/system/auditing/auditd_configure_rules/file_permissions_var_log_audit/ansible/shared.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
- name: Parse log file line
1313
command: awk -F '=' '/^log_file/ {print $2}' /etc/audit/auditd.conf
1414
register: log_file_line
15-
when: (log_file_exists.stdout | length > 0)
15+
when: log_file_exists is not skipped and (log_file_exists.stdout | length > 0)
1616

1717
- name: Set default log_file if not set
1818
set_fact:
1919
log_file: "/var/log/audit/audit.log"
20-
when: (log_file_exists is undefined) or (log_file_exists.stdout | length == 0)
20+
when: (log_file_exists is skipped) or (log_file_exists is undefined) or (log_file_exists.stdout | length == 0)
2121

2222
- name: Set log_file from log_file_line if not set already
2323
set_fact:
2424
log_file: "{{ log_file_line.stdout | trim }}"
25-
when: (log_file_line.stdout is defined) and (log_file_line.stdout | length > 0)
25+
when: (log_file_exists is not skipped) and (log_file_line.stdout is defined) and (log_file_line.stdout | length > 0)
2626

2727
{{% if 'ol' not in product and "rhel" not in product %}}
2828
- name: Get log files group
@@ -33,13 +33,14 @@
3333
- name: Parse log group line
3434
command: awk -F '=' '/log_group/ {print $2}' /etc/audit/auditd.conf
3535
register: log_group
36-
when: (log_group_line.stdout | length > 0)
36+
when: (log_group_line is not skipped) and (log_group_line.stdout | length > 0)
3737

3838
- name: Apply mode to log file when group root
3939
file:
4040
path: "{{ log_file }}"
4141
mode: (( log_group is defined ) and ( ( log_group.stdout | trim ) == 'root' )) | ternary( '0600', '0640')
4242
failed_when: false
43+
when: log_group is not skipped
4344

4445
- name: List all log file backups
4546
find:
@@ -53,6 +54,7 @@
5354
mode: (( log_group is defined ) and ( ( log_group.stdout | trim ) == 'root' )) | ternary( '0400', '0440')
5455
loop: "{{ backup_files.files| map(attribute='path') | list }}"
5556
failed_when: false
57+
when: backup_files is not skipped
5658

5759
{{% else %}}
5860
- name: Apply mode to log file

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
value: '1'
2424
no_extra_spaces: True
2525
# regex filters grep output for files ending in .repo and matching section names.
26-
loop: "{{ repo_grep_results.stdout | regex_findall( '(.+\\.repo):\\[(.+)\\]\\n?' ) }}"
26+
loop: "{{ repo_grep_results.stdout |regex_findall( '(.+\\.repo):\\[(.+)\\]\\n?' ) if repo_grep_results is not skipped else []}}"
27+
when: repo_grep_results is not skipped

shared/macros/10-ansible.jinja

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,21 +1268,21 @@ Part of the grub2_bootloader_argument template.
12681268
dest: /etc/default/grub
12691269
create: yes
12701270
mode: '0644'
1271-
when: argcheck.rc != 0 and linecheck.rc != 0
1271+
when: argcheck is not skipped and linecheck is not skipped and argcheck.rc != 0 and linecheck.rc != 0
12721272

12731273
- name: Replace existing {{{ arg_name }}} argument
12741274
replace:
12751275
path: /etc/default/grub
12761276
regexp: '{{{ arg_name }}}=[a-zA-Z0-9,]+'
12771277
replace: '{{{ arg_name_value }}}'
1278-
when: argcheck.rc == 0 and linecheck.rc == 0
1278+
when: argcheck is not skipped and linecheck is not skipped and argcheck.rc == 0 and linecheck.rc == 0
12791279

12801280
- name: Add {{{ arg_name }}} argument
12811281
replace:
12821282
path: /etc/default/grub
12831283
regexp: '(^\s*GRUB_CMDLINE_LINUX=.*)"'
12841284
replace: '\1 {{{ arg_name_value }}}"'
1285-
when: argcheck.rc != 0 and linecheck.rc == 0
1285+
when: argcheck is not skipped and linecheck is not skipped and argcheck.rc != 0 and linecheck.rc == 0
12861286

12871287
{{% endif -%}}
12881288

@@ -1319,7 +1319,7 @@ Part of the grub2_bootloader_argument_absent template.
13191319
path: /etc/default/grub
13201320
regexp: '\(^GRUB_CMDLINE_LINUX=".*\){{{ arg_name }}}=?[^[:space:]]*\(.*"\)'
13211321
replace: '\1 \2'
1322-
when: argcheck.rc == 0
1322+
when: argcheck is not skipped and argcheck.rc == 0
13231323

13241324
{{% endif -%}}
13251325

shared/templates/rsyslog_logfiles_attributes_modify/ansible.template

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- name: '{{{ rule_title }}} - Aggregate rsyslog includes'
3333
ansible.builtin.set_fact:
3434
include_config_output: "{{ rsyslog_old_inc.stdout_lines + rsyslog_new_inc.stdout_lines }}"
35+
when: rsyslog_old_inc is not skipped and rsyslog_new_inc is not skipped
3536

3637
- name: '{{{ rule_title }}} - List all config files'
3738
ansible.builtin.find:
@@ -40,6 +41,7 @@
4041
hidden: no
4142
follow: yes
4243
loop: "{{ include_config_output | list + [rsyslog_etc_config] }}"
44+
when: include_config_output is defined
4345
register: rsyslog_config_files
4446
failed_when: False
4547
changed_when: False
@@ -51,9 +53,10 @@
5153
grep -oP '^[^(\s|#|\$)]+[\s]+.*[\s]+-?(/+[^:;\s]+);*\.*$' {{ item.1.path }} | \
5254
awk '{print $NF}' | \
5355
sed -e 's/^-//' || true
54-
loop: "{{ rsyslog_config_files.results | subelements('files') }}"
56+
loop: "{{ rsyslog_config_files.results | default([]) | subelements('files') }}"
5557
register: log_files_old
5658
changed_when: False
59+
when: rsyslog_config_files is not skipped
5760

5861
- name: '{{{ rule_title }}} - Extract log files new format'
5962
ansible.builtin.shell: |
@@ -63,9 +66,10 @@
6366
grep -aoP "File\s*=\s*\"([/[:alnum:][:punct:]]*)\"\s*\)" | \
6467
grep -oE "\"([/[:alnum:][:punct:]]*)\"" | \
6568
tr -d "\""|| true
66-
loop: "{{ rsyslog_config_files.results | subelements('files') }}"
69+
loop: "{{ rsyslog_config_files.results | default([]) | subelements('files') }}"
6770
register: log_files_new
6871
changed_when: False
72+
when: rsyslog_config_files is not skipped
6973

7074
- name: '{{{ rule_title }}} - Sum all log files found'
7175
ansible.builtin.set_fact:

0 commit comments

Comments
 (0)