Skip to content

Commit 6c3db67

Browse files
committed
Consistently access facts via the ansible_facts.* namespace
Signed-off-by: Norman Ziegner <[email protected]>
1 parent 819fc1a commit 6c3db67

File tree

16 files changed

+37
-36
lines changed

16 files changed

+37
-36
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/molecule.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ provisioner:
2222
defaults:
2323
interpreter_python: auto_silent
2424
callbacks_enabled: profile_tasks, timer
25-
inject_facts_as_vars: false
25+
# Currently not supported by geerlingguy.nginx role
26+
# inject_facts_as_vars: false
2627
verifier:
2728
name: ansible
2829

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/verify_tasks/pw_ageing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# this uses the date from the expire_date variable and subtracts the current date.
2020
# it should be bigger that the password_expire_min of the user "pw_no_ageing"
2121
that:
22-
- ( expiry_date.stdout | trim | to_datetime('%b %d, %Y') - ansible_date_time.date | to_datetime('%Y-%m-%d')).days == 60
22+
- ( expiry_date.stdout | trim | to_datetime('%b %d, %Y') - ansible_facts.date_time.date | to_datetime('%Y-%m-%d')).days == 60
2323

2424
- name: Get Password Expiry warning days for pw_ageing
2525
ansible.builtin.shell: chage -l pw_ageing | grep "warning before password expires" | cut -d ":" -f 2

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:

0 commit comments

Comments
 (0)