Skip to content

Commit

Permalink
Simplify ansible remediation of auditd_name_format.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggbecker committed Sep 12, 2023
1 parent 9a278cc commit d2e983e
Showing 1 changed file with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,13 @@

{{{ ansible_instantiate_variables("var_auditd_name_format") }}}

- name: "{{{ rule_title }}} - Set type of computer node name logging in audit logs"
block:
- name: Check for duplicate values
ansible.builtin.lineinfile:
path: "{{{ auditd_conf_path }}}"
create: true
regexp: (?i)^\s*name_format\s*=\s*
state: absent
check_mode: true
changed_when: false
register: dupes
- name: "{{{ rule_title }}} - Define value to be used in the remediation"
ansible.builtin.set_fact: auditd_name_format_split="{{ var_auditd_name_format.split('|')[0] }}"

- name: "{{{ rule_title }}} - Deduplicate values from {{{ auditd_conf_path }}}"
ansible.builtin.lineinfile:
path: "{{{ auditd_conf_path }}}"
create: true
regexp: (?i)^\s*name_format\s*=\s*
state: absent
when: dupes.found is defined and dupes.found > 1

- name: "{{{ rule_title }}} - Insert correct line to {{{ auditd_conf_path }}}"
ansible.builtin.lineinfile:
path: "{{{ auditd_conf_path }}}"
create: true
regexp: (?i)^\s*name_format\s*=\s*
line: name_format = {{ var_auditd_name_format.split('|')[0] }}
state: present
{{{ ansible_set_config_file(file=auditd_conf_path,
parameter="name_format",
value="{{ auditd_name_format_split }}",
create=true,
separator=" = ",
separator_regex="\s*=\s*",
prefix_regex="(?i)^\s*") }}}

0 comments on commit d2e983e

Please sign in to comment.