Skip to content

Commit 0131f33

Browse files
committed
refactor: handle INJECT_FACTS_AS_VARS=false by using ansible_facts instead
Ansible 2.20 has deprecated the use of Ansible facts as variables. For example, `ansible_distribution` is now deprecated in favor of `ansible_facts["distribution"]`. This is due to making the default setting `INJECT_FACTS_AS_VARS=false`. For now, this will create WARNING messages, but in Ansible 2.24 it will be an error. See https://docs.ansible.com/projects/ansible/latest/porting_guides/porting_guide_core_2.20.html#inject-facts-as-vars Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent c7392be commit 0131f33

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

tasks/insights-client.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156

157157
- name: Configure remediation
158158
when:
159-
- ansible_distribution_version is version("8.4", ">=")
159+
- ansible_facts['distribution_version'] is version("8.4", ">=")
160160
- rhc_insights.remediation | d("present") == "present"
161161
block:
162162
- name: Ensure worker and ansible packages are installed

tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- name: Handle insights unregistration
77
include_tasks: insights-client-unregistration.yml
88
when:
9-
- ansible_distribution == "RedHat"
9+
- ansible_facts['distribution'] == "RedHat"
1010
- >-
1111
rhc_insights.state | d("present") == "absent"
1212
or rhc_state | d("present") in ["absent", "reconnect"]
@@ -18,6 +18,6 @@
1818
- name: Handle insights registration
1919
include_tasks: insights-client.yml
2020
when:
21-
- ansible_distribution == "RedHat"
21+
- ansible_facts['distribution'] == "RedHat"
2222
- rhc_insights.state | d("present") == "present"
2323
- rhc_state | d("present") in ["present", "reconnect"]

tasks/set_vars.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- name: Check if insights-packages are installed
2222
package_facts:
2323
when:
24-
- ansible_distribution == "RedHat"
24+
- ansible_facts['distribution'] == "RedHat"
2525
- >-
2626
rhc_insights.state | d("present") == "absent"
2727
or rhc_state | d("present") in ["absent", "reconnect"]

tests/tasks/setup_candlepin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
- --publish
5656
- 8080:8080
5757
- "{{ '--privileged'
58-
if (ansible_distribution in ['CentOS', 'RedHat']
59-
and ansible_distribution_major_version | int < 8)
58+
if (ansible_facts['distribution'] in ['CentOS', 'RedHat']
59+
and ansible_facts['distribution_major_version'] | int < 8)
6060
else '' }}"
6161
- ghcr.io/candlepin/candlepin-unofficial
6262
command:

tests/tests_environments.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
- name: Check the enabled environments
8787
when:
8888
- >-
89-
ansible_distribution not in ["CentOS", "RedHat"]
90-
or (ansible_distribution == "CentOS"
91-
and ansible_distribution_major_version | int >= 8)
92-
or (ansible_distribution_version is version("8.6", ">="))
89+
ansible_facts["distribution"] not in ["CentOS", "RedHat"]
90+
or (ansible_facts["distribution"] == "CentOS"
91+
and ansible_facts["distribution_major_version"] | int >= 8)
92+
or (ansible_facts["distribution_version"] is version("8.6", ">="))
9393
block:
9494
- name: Get enabled environments
9595
include_tasks: tasks/list_environments.yml

tests/tests_insights_remediation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- name: Skip if the RHEL version is older than 8.4
1919
meta: end_play
2020
when:
21-
- ansible_distribution_version is version("8.4", "<")
21+
- ansible_facts["distribution_version"] is version("8.4", "<")
2222

2323
- name: Test remediation
2424
block:

tests/vars/rh_distros_vars.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ __rhc_rh_distros:
1414
__rhc_rh_distros_fedora: "{{ __rhc_rh_distros + ['Fedora'] }}"
1515

1616
# Use this in conditionals to check if distro is Red Hat or clone
17-
__rhc_is_rh_distro: "{{ ansible_distribution in __rhc_rh_distros }}"
17+
__rhc_is_rh_distro: "{{ ansible_facts['distribution'] in __rhc_rh_distros }}"
1818

1919
# Use this in conditionals to check if distro is Red Hat or clone, or Fedora
20-
__rhc_is_rh_distro_fedora: "{{ ansible_distribution in __rhc_rh_distros_fedora }}"
20+
__rhc_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __rhc_rh_distros_fedora }}"

vars/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ __rhc_insights_tags: "/etc/insights-client/tags.yaml"
2929
# to Insights, used for remediations; starting from EL 10 the service is the
3030
# upstream one, and no more the downstream-branded one
3131
__rhc_yggdrasil_systemd_service: "{{ 'yggdrasil'
32-
if (ansible_distribution_major_version | int >= 10)
32+
if (ansible_facts['distribution_major_version'] | int >= 10)
3333
else 'rhcd' }}"
3434

3535
# BEGIN - DO NOT EDIT THIS BLOCK - rh distros variables
@@ -44,8 +44,8 @@ __rhc_rh_distros:
4444
__rhc_rh_distros_fedora: "{{ __rhc_rh_distros + ['Fedora'] }}"
4545

4646
# Use this in conditionals to check if distro is Red Hat or clone
47-
__rhc_is_rh_distro: "{{ ansible_distribution in __rhc_rh_distros }}"
47+
__rhc_is_rh_distro: "{{ ansible_facts['distribution'] in __rhc_rh_distros }}"
4848

4949
# Use this in conditionals to check if distro is Red Hat or clone, or Fedora
50-
__rhc_is_rh_distro_fedora: "{{ ansible_distribution in __rhc_rh_distros_fedora }}"
50+
__rhc_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __rhc_rh_distros_fedora }}"
5151
# END - DO NOT EDIT THIS BLOCK - rh distros variables

0 commit comments

Comments
 (0)