Skip to content

Commit a8764a3

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 09fa38c commit a8764a3

6 files changed

Lines changed: 13 additions & 11 deletions

File tree

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`

tasks/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
# NOTE: Trying to accomplish this without using sudo on the controller
2525
# Basically, any task, even package_facts:, will use sudo if using
2626
# become=true - so just use "exists" test to check for /usr/bin/openssl
27+
# If you really want the role to install openssl on the controller, you must run
28+
# ansible with become=true e.g. ansible-playbook --become ...
2729
- name: Ensure OpenSSL is installed on the controller
2830
package:
2931
name: openssl

tasks/mesh_conf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
block:
77
- name: Set current IP fact for each host
88
set_fact:
9-
__vpn_current_ip: "{{ ansible_default_ipv4.address | d(ansible_default_ipv6.address) }}"
9+
__vpn_current_ip: "{{ ansible_facts['default_ipv4'].address | d(ansible_facts['default_ipv6'].address) }}"
1010

1111
- name: Set IP with prefix register
1212
shell: |-

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 @@ __vpn_rh_distros:
1414
__vpn_rh_distros_fedora: "{{ __vpn_rh_distros + ['Fedora'] }}"
1515

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

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

vars/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ __vpn_rh_distros:
3737
__vpn_rh_distros_fedora: "{{ __vpn_rh_distros + ['Fedora'] }}"
3838

3939
# Use this in conditionals to check if distro is Red Hat or clone
40-
__vpn_is_rh_distro: "{{ ansible_distribution in __vpn_rh_distros }}"
40+
__vpn_is_rh_distro: "{{ ansible_facts['distribution'] in __vpn_rh_distros }}"
4141

4242
# Use this in conditionals to check if distro is Red Hat or clone, or Fedora
43-
__vpn_is_rh_distro_fedora: "{{ ansible_distribution in __vpn_rh_distros_fedora }}"
43+
__vpn_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __vpn_rh_distros_fedora }}"
4444
# END - DO NOT EDIT THIS BLOCK - rh distros variables

0 commit comments

Comments
 (0)