Skip to content

Commit b06cb0e

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 4a82780 commit b06cb0e

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`

tests/tests_default.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
- name: Verify that /run/log/journal/$MACHINE_ID/system.journal exists
2525
stat:
26-
path: /run/log/journal/{{ ansible_machine_id }}/system.journal
26+
path: /run/log/journal/{{ ansible_facts['machine_id'] }}/system.journal
2727
register: __stat
2828
failed_when: not __stat.stat.exists
2929

@@ -32,7 +32,7 @@
3232
cmd: >
3333
set -euo pipefail;
3434
journalctl --header
35-
--file /run/log/journal/{{ ansible_machine_id }}/system.journal |
35+
--file /run/log/journal/{{ ansible_facts['machine_id'] }}/system.journal |
3636
grep -q 'State: ONLINE'
3737
changed_when: false
3838

@@ -41,6 +41,6 @@
4141
cmd: >
4242
set -euo pipefail;
4343
journalctl --header
44-
--file /run/log/journal/{{ ansible_machine_id }}/system.journal |
44+
--file /run/log/journal/{{ ansible_facts['machine_id'] }}/system.journal |
4545
grep -q COMPRESSED
4646
changed_when: false

tests/tests_example.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104

105105
- name: Verify that /var/log/journal/$MACHINE_ID/system.journal exists
106106
stat:
107-
path: /var/log/journal/{{ ansible_machine_id }}/system.journal
107+
path: /var/log/journal/{{ ansible_facts['machine_id'] }}/system.journal
108108
register: __stat
109109
failed_when: not __stat.stat.exists
110110

@@ -113,7 +113,7 @@
113113
cmd: >
114114
set -euo pipefail;
115115
journalctl --header
116-
--file /var/log/journal/{{ ansible_machine_id }}/system.journal |
116+
--file /var/log/journal/{{ ansible_facts['machine_id'] }}/system.journal |
117117
grep -q 'State: ONLINE'
118118
changed_when: false
119119

@@ -122,7 +122,7 @@
122122
cmd: >
123123
set -euo pipefail;
124124
journalctl --header
125-
--file /var/log/journal/{{ ansible_machine_id }}/system.journal |
125+
--file /var/log/journal/{{ ansible_facts['machine_id'] }}/system.journal |
126126
grep -q COMPRESSED
127127
changed_when: false
128128

tests/vars/rh_distros_vars.yml

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

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

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

vars/main.yml

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

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

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

0 commit comments

Comments
 (0)