Skip to content

Commit cc5d0d8

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 <[email protected]>
1 parent 9352879 commit cc5d0d8

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

README-ostree.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Usage:
2020
.ostree/get_ostree_data.sh packages runtime DISTRO-VERSION FORMAT
2121
```
2222

23-
`DISTRO-VERSION` is in the format that Ansible uses for `ansible_distribution`
24-
and `ansible_distribution_version` - for example, `Fedora-38`, `CentOS-8`,
23+
`DISTRO-VERSION` is in the format that Ansible uses for `ansible_facts["distribution"]`
24+
and `ansible_facts["distribution_version"]` - for example, `Fedora-38`, `CentOS-8`,
2525
`RedHat-9.4`
2626

2727
`FORMAT` is one of `toml`, `json`, `yaml`, `raw`

tests/tests_include_vars_from_parent.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
# create all variants like CentOS, CentOS_8.1, CentOS-8.1,
3131
# CentOS-8, CentOS-8.1
3232
# more formally:
33-
# {{ ansible_distribution }}-{{ ansible_distribution_version }}
34-
# {{ ansible_distribution }}-{{ ansible_distribution_major_version }}
35-
# {{ ansible_distribution }}
36-
# {{ ansible_os_family }}
33+
# {{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_version"] }}
34+
# {{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"] }}
35+
# {{ ansible_facts["distribution"] }}
36+
# {{ ansible_facts["os_family"] }}
3737
# and the same for _ as separator.
3838
varfiles: "{{ [facts['distribution']] | product(separators) |
3939
map('join') | product(versions) | map('join') | list +

tests/vars/rh_distros_vars.yml

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

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

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

vars/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ __ssh_rh_distros:
3838
__ssh_rh_distros_fedora: "{{ __ssh_rh_distros + ['Fedora'] }}"
3939

4040
# Use this in conditionals to check if distro is Red Hat or clone
41-
__ssh_is_rh_distro: "{{ ansible_distribution in __ssh_rh_distros }}"
41+
__ssh_is_rh_distro: "{{ ansible_facts['distribution'] in __ssh_rh_distros }}"
4242

4343
# Use this in conditionals to check if distro is Red Hat or clone, or Fedora
44-
__ssh_is_rh_distro_fedora: "{{ ansible_distribution in __ssh_rh_distros_fedora }}"
44+
__ssh_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __ssh_rh_distros_fedora }}"
4545
# END - DO NOT EDIT THIS BLOCK - rh distros variables

0 commit comments

Comments
 (0)