Skip to content

Commit 2372abd

Browse files
authored
Merge pull request #846 from Tinyblargon/reduce-set-fact
Refactor: combine multiple set_fact into single jinja filter
2 parents 3be6a3b + 85415e7 commit 2372abd

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

roles/os_hardening/tasks/sysctl.yml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@
2121
- name: Change sysctls
2222
when: ansible_virtualization_type not in ['docker', 'lxc', 'openvz']
2323
block:
24-
- name: Create a combined sysctl-dict if os-dependent sysctls are defined
25-
ansible.builtin.set_fact:
26-
sysctl_config: "{{ sysctl_config | combine(sysctl_custom_config) }}"
27-
when: sysctl_custom_config | default()
28-
29-
# sysctl_rhel_config is kept for backwards-compatibility. use sysctl_custom_config instead
30-
- name: Create a combined sysctl-dict if os-dependent sysctls are defined
31-
ansible.builtin.set_fact:
32-
sysctl_config: "{{ sysctl_config | combine(sysctl_rhel_config) }}"
33-
when: sysctl_rhel_config | default()
34-
35-
- name: Create a combined sysctl-dict if overwrites are defined
36-
ansible.builtin.set_fact:
37-
sysctl_config: "{{ sysctl_config | combine(sysctl_overwrite) }}"
38-
when: sysctl_overwrite | default()
39-
4024
- name: Change various sysctl-settings, look at the sysctl-vars file for documentation
4125
ansible.posix.sysctl:
4226
name: "{{ item.key }}"
@@ -45,7 +29,12 @@
4529
state: present
4630
reload: true
4731
ignoreerrors: true
48-
with_dict: "{{ sysctl_config }}"
32+
# sysctl_rhel_config is kept for backwards-compatibility. use sysctl_custom_config instead
33+
# combines all sysctl-dicts into one, adds empty dicts if they are not defined
34+
with_dict: "{{ ((sysctl_config
35+
| combine(sysctl_custom_config | default({})))
36+
| combine(sysctl_rhel_config | default({})))
37+
| combine(sysctl_overwrite | default({})) }}"
4938
when: item.key not in sysctl_unsupported_entries | default()
5039

5140
- name: Apply ufw defaults

0 commit comments

Comments
 (0)