Skip to content

Commit 1d48619

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 bd7cec3 commit 1d48619

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
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`

tasks/manage_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- name: Apply changes
44
when: __postfix_has_config_changed | d("") is search("True")
55
block:
6-
- name: Gather facts for ansible_date_time
6+
- name: Gather facts for ansible_facts["date_time"]
77
setup:
88
filter: ansible_date_time
99
when: postfix_backup_multiple | bool
@@ -13,7 +13,7 @@
1313
remote_src: true
1414
src: /etc/postfix/main.cf
1515
dest: /etc/postfix/main.cf.{{ postfix_backup_multiple |
16-
ternary(ansible_date_time.iso8601, "backup") }}
16+
ternary(ansible_facts['date_time']['iso8601'], "backup") }}
1717
mode: "0644"
1818
when: postfix_backup or postfix_backup_multiple
1919

tasks/set_facts.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
- name: Set platform/version specific variables
2222
include_vars: "{{ __postfix_vars_file }}"
2323
loop:
24-
- "{{ ansible_os_family }}.yml"
25-
- "{{ ansible_distribution }}.yml"
26-
- "{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yml"
27-
- "{{ ansible_distribution }}_{{ ansible_distribution_version }}.yml"
24+
- "{{ ansible_facts['os_family'] }}.yml"
25+
- "{{ ansible_facts['distribution'] }}.yml"
26+
- "{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_major_version'] }}.yml"
27+
- "{{ ansible_facts['distribution'] }}_{{ ansible_facts['distribution_version'] }}.yml"
2828
vars:
2929
__postfix_vars_file: "{{ role_path }}/vars/{{ item }}"
3030
when: __postfix_vars_file is file

tests/vars/rh_distros_vars.yml

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

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

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

vars/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ __postfix_rh_distros:
3232
__postfix_rh_distros_fedora: "{{ __postfix_rh_distros + ['Fedora'] }}"
3333

3434
# Use this in conditionals to check if distro is Red Hat or clone
35-
__postfix_is_rh_distro: "{{ ansible_distribution in __postfix_rh_distros }}"
35+
__postfix_is_rh_distro: "{{ ansible_facts['distribution'] in __postfix_rh_distros }}"
3636

3737
# Use this in conditionals to check if distro is Red Hat or clone, or Fedora
38-
__postfix_is_rh_distro_fedora: "{{ ansible_distribution in __postfix_rh_distros_fedora }}"
38+
__postfix_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __postfix_rh_distros_fedora }}"
3939
# END - DO NOT EDIT THIS BLOCK - rh distros variables

0 commit comments

Comments
 (0)