Skip to content

Commit

Permalink
modify the Ansible remediation so that Jinja is not evaluated in the …
Browse files Browse the repository at this point in the history
…when conditional

The evaluation is done in a separate task and saved as a fact.
  • Loading branch information
vojtapolasek committed Jul 10, 2024
1 parent c9dda20 commit af1e41c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
- path: "{{{ DROPIN_DIR }}}"
pattern: "*.conf"

- name: "{{{ rule_title }}} - Count number of files which contain the correct section"
ansible.builtin.set_fact:
count_of_systemd_dropin_files_with_section: "{{systemd_dropin_files_with_section.results | map(attribute='matched') | list | map('int') | sum}}"

- name: "{{{ rule_title }}} - Add missing configuration to correct section"
ini_file:
path: "{{item}}"
Expand All @@ -29,7 +33,7 @@
{{% endif %}}
state: present
no_extra_spaces: true
when: "{{systemd_dropin_files_with_section.results | map(attribute='matched') | list | map('int') | sum > 0}}"
when: count_of_systemd_dropin_files_with_section | int > 0
loop: "{{systemd_dropin_files_with_section.results | sum(attribute='files', start=[]) | map(attribute='path') | list }}"

- name: "{{{ rule_title }}} - Add configuration to new remediation file"
Expand All @@ -45,4 +49,4 @@
state: present
no_extra_spaces: true
create: true
when: "{{systemd_dropin_files_with_section.results | map(attribute='matched') | list | map('int') | sum == 0}}"
when: count_of_systemd_dropin_files_with_section | int == 0

0 comments on commit af1e41c

Please sign in to comment.