Skip to content

Commit 40e7b02

Browse files
committed
Consistently access facts via the ansible_facts.* namespace
Signed-off-by: Norman Ziegner <[email protected]>
1 parent 482c78b commit 40e7b02

File tree

11 files changed

+31
-31
lines changed

11 files changed

+31
-31
lines changed

molecule/mysql_hardening/converge.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
mysql_python_package_debian: python3-pymysql
1313
when:
1414
- mysql_python_package_debian is not defined
15-
- ansible_distribution == "Ubuntu"
16-
- ansible_distribution_major_version|int > 19
15+
- ansible_facts.distribution == "Ubuntu"
16+
- ansible_facts.distribution_major_version|int > 19
1717

1818
- name: Determine required MySQL Python libraries.
1919
ansible.builtin.set_fact:
2020
mysql_python_package_debian: "{% if 'python3' in ansible_python_interpreter | default('') %}python3-mysqldb{% else %}python-mysqldb{% endif %}"
2121
when:
2222
- mysql_python_package_debian is not defined
23-
- ansible_distribution != "Ubuntu"
24-
- ansible_distribution_major_version|int < 20
23+
- ansible_facts.distribution != "Ubuntu"
24+
- ansible_facts.distribution_major_version|int < 20
2525

2626
- name: Use Python 3 on Suse
2727
ansible.builtin.set_fact:
2828
ansible_python_interpreter: /usr/bin/python3
2929
when:
30-
- ansible_os_family == 'Suse'
30+
- ansible_facts.os_family == 'Suse'
3131

3232
- name: Include mysql_hardening role
3333
ansible.builtin.include_role:

molecule/mysql_hardening/prepare.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@
1717
ansible.builtin.set_fact:
1818
ansible_python_interpreter: /usr/bin/python3
1919
when:
20-
- ansible_distribution == 'Debian'
21-
- ansible_distribution_major_version|int >= 11
20+
- ansible_facts.distribution == 'Debian'
21+
- ansible_facts.distribution_major_version|int >= 11
2222

2323
- name: Use Python 3 on Suse
2424
ansible.builtin.set_fact:
2525
ansible_python_interpreter: /usr/bin/python3
2626
when:
27-
- ansible_os_family == 'Suse'
27+
- ansible_facts.os_family == 'Suse'
2828

2929
- name: Run the equivalent of "apt-get update && apt-get upgrade"
3030
ansible.builtin.apt:
3131
upgrade: safe
3232
update_cache: true
33-
when: ansible_os_family == 'Debian'
33+
when: ansible_facts.os_family == 'Debian'
3434

3535
- name: Install required python packages on Suse
3636
ansible.builtin.command: zypper -n install python311-rpm python311-PyMySQL
3737
changed_when: false
38-
when: ansible_os_family == 'Suse'
38+
when: ansible_facts.os_family == 'Suse'
3939

4040
- name: Create missing directory
4141
ansible.builtin.file:
@@ -48,23 +48,23 @@
4848
mysql_python_package_debian: python3-pymysql
4949
when:
5050
- mysql_python_package_debian is not defined
51-
- ansible_distribution == "Ubuntu"
52-
- ansible_distribution_major_version|int > 19
51+
- ansible_facts.distribution == "Ubuntu"
52+
- ansible_facts.distribution_major_version|int > 19
5353

5454
- name: Determine required MySQL Python libraries.
5555
ansible.builtin.set_fact:
5656
mysql_python_package_debian: "{% if 'python3' in ansible_python_interpreter | default('') %}python3-mysqldb{% else %}python-mysqldb{% endif %}"
5757
when:
5858
- mysql_python_package_debian is not defined
59-
- ansible_distribution != "Ubuntu"
60-
- ansible_distribution_major_version|int < 20
59+
- ansible_facts.distribution != "Ubuntu"
60+
- ansible_facts.distribution_major_version|int < 20
6161

6262
- name: Install required MySQL Python libraries on RHEL
6363
ansible.builtin.dnf:
6464
name: "{% if 'python3' in ansible_python_interpreter | default('') %}python36-PyMySQL{% else %}python2-PyMySQL{% endif %}"
6565
when:
66-
- ansible_os_family == "RedHat"
67-
- ansible_distribution_major_version == "7"
66+
- ansible_facts.os_family == "RedHat"
67+
- ansible_facts.distribution_major_version == "7"
6868

6969
- name: Install mysql with a generic Ansible role
7070
ansible.builtin.include_role:

molecule/mysql_hardening/verify.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
ansible.builtin.set_fact:
1212
ansible_python_interpreter: /usr/bin/python3
1313
when:
14-
- ansible_os_family == 'Suse'
14+
- ansible_facts.os_family == 'Suse'
1515

1616
- name: Install procps for debian systems
1717
ansible.builtin.apt:
1818
name: procps
1919
state: present
2020
update_cache: true
21-
when: ansible_distribution == 'Debian'
21+
when: ansible_facts.distribution == 'Debian'
2222

2323
- name: Include tests for the service
2424
ansible.builtin.include_tasks: verify_tasks/service.yml

molecule/nginx_hardening/prepare.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
- name: Set correct distribution Version for Amazon Linux
1717
ansible.builtin.set_fact:
1818
ansible_distribution_major_version: 7
19-
when: ansible_distribution == 'Amazon'
19+
when: ansible_facts.distribution == 'Amazon'
2020

2121
- name: Install nginx with a generic Ansible role
2222
ansible.builtin.include_role:

molecule/nginx_hardening/verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
name: procps
1313
state: present
1414
update_cache: true
15-
when: ansible_distribution == 'Debian'
15+
when: ansible_facts.distribution == 'Debian'
1616

1717
- name: Verify
1818
hosts: localhost

molecule/os_hardening/prepare.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
ansible.builtin.apt:
1717
upgrade: safe
1818
update_cache: true
19-
when: ansible_os_family == 'Debian'
19+
when: ansible_facts.os_family == 'Debian'
2020

2121
- name: Install required tools on SuSE
2222
# cannot use zypper module, since it depends on python-xml

molecule/os_hardening_vm/converge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
os_mnt_var_options: rw,nosuid,nodev,compress=zstd:1,subvol=var
3131
when:
3232
- ansible_facts.distribution == 'Fedora'
33-
- ansible_distribution_major_version|int == 40
33+
- ansible_facts.distribution_major_version|int == 40
3434

3535
- name: Include os_hardening role
3636
ansible.builtin.include_role:

molecule/os_hardening_vm/prepare.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
ansible.builtin.dpkg_selections:
2727
name: grub-pc
2828
selection: hold
29-
when: ansible_os_family == 'Debian'
29+
when: ansible_facts.os_family == 'Debian'
3030

3131
# we need to free up space, since the /boot partition in some Vagrant images is
3232
# pretty small and system updates might fail
@@ -35,20 +35,20 @@
3535
paths: /boot
3636
patterns: "initrd.img*"
3737
register: find_results
38-
when: ansible_os_family == 'Debian'
38+
when: ansible_facts.os_family == 'Debian'
3939

4040
- name: Delete all initrd.img to free space on /boot
4141
ansible.builtin.file:
4242
path: "{{ item['path'] }}"
4343
state: absent
4444
with_items: "{{ find_results['files'] }}"
45-
when: ansible_os_family == 'Debian'
45+
when: ansible_facts.os_family == 'Debian'
4646

4747
- name: Run the equivalent of "apt-get update && apt-get upgrade"
4848
ansible.builtin.apt:
4949
upgrade: safe
5050
update_cache: true
51-
when: ansible_os_family == 'Debian'
51+
when: ansible_facts.os_family == 'Debian'
5252

5353
- name: Install required tools on fedora
5454
ansible.builtin.dnf:

roles/os_hardening/tasks/ctrlaltdel.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
name: ctrl-alt-del.target
55
masked: true
66
daemon_reload: true
7-
when: ansible_service_mgr == "systemd"
7+
when: ansible_facts.service_mgr == "systemd"

roles/os_hardening/tasks/limits.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
group: root
3838
mode: "0755"
3939
state: directory
40-
when: ansible_service_mgr == "systemd"
40+
when: ansible_facts.service_mgr == "systemd"
4141

4242
- name: Create custom.conf for disabling coredumps
4343
ansible.builtin.template:
@@ -46,7 +46,7 @@
4646
owner: root
4747
group: root
4848
mode: "0644"
49-
when: ansible_service_mgr == "systemd"
49+
when: ansible_facts.service_mgr == "systemd"
5050
notify: Reload systemd
5151

5252
- name: Enable coredumps
@@ -56,7 +56,7 @@
5656
ansible.builtin.file:
5757
path: /etc/systemd/coredump.conf.d
5858
state: absent
59-
when: ansible_service_mgr == "systemd"
59+
when: ansible_facts.service_mgr == "systemd"
6060
notify: Reload systemd
6161

6262
- name: Remove 10.hardcore.conf config file

0 commit comments

Comments
 (0)