Skip to content

Commit 39ebc19

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 00632c1 commit 39ebc19

10 files changed

Lines changed: 32 additions & 23 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`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ To configure the private key of the logging system, `private_key_src` and/or `pr
486486

487487
#### logging_domain
488488

489-
The default DNS domain used to accept remote incoming logs from remote hosts. Default to "{{ ansible_domain if ansible_domain else ansible_hostname }}"
489+
The default DNS domain used to accept remote incoming logs from remote hosts. Default to "{{ ansible_facts['domain'] if ansible_facts['domain'] else ansible_facts['hostname'] }}"
490490

491491
### Server performance optimization options
492492

defaults/main.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ logging_pki_files: []
7979
# logging_domain
8080
#
8181
# The default DNS domain used to accept remote incoming logs from remote hosts.
82-
logging_domain: '{{ ansible_domain if ansible_domain else ansible_hostname }}'
82+
logging_domain: '{{ ansible_facts["domain"] if ansible_facts["domain"] else ansible_facts["hostname"] }}'
8383

8484
# logging_elasticsearch_password
8585
#
@@ -125,17 +125,26 @@ logging_custom_templates: []
125125

126126
# ansible_facts required by the role
127127
__logging_required_facts:
128+
- default_ipv4 # requires the iproute package for the ip command
128129
- distribution
129130
- distribution_major_version
130131
- distribution_version
132+
- domain
133+
- fqdn
134+
- hostname
131135
- os_family
132-
- default_ipv4 # requires the iproute package for the ip command
136+
- pkg_mgr
137+
138+
__logging_no_subsets_facts:
139+
- domain
140+
- fqdn
141+
- hostname
133142

134143
# the subsets of ansible_facts that need to be gathered in case any of the
135144
# facts in required_facts is missing; see the documentation of
136145
# the 'gather_subset' parameter of the 'setup' module
137146
__logging_required_facts_subsets: "{{ ['!all', '!min'] +
138-
__logging_required_facts }}"
147+
__logging_required_facts | difference(__logging_no_subsets_facts) }}"
139148

140149
# BEGIN - DO NOT EDIT THIS BLOCK - rh distros variables
141150
# Ansible distribution identifiers that the role treats like RHEL
@@ -149,8 +158,8 @@ __logging_rh_distros:
149158
__logging_rh_distros_fedora: "{{ __logging_rh_distros + ['Fedora'] }}"
150159

151160
# Use this in conditionals to check if distro is Red Hat or clone
152-
__logging_is_rh_distro: "{{ ansible_distribution in __logging_rh_distros }}"
161+
__logging_is_rh_distro: "{{ ansible_facts['distribution'] in __logging_rh_distros }}"
153162

154163
# Use this in conditionals to check if distro is Red Hat or clone, or Fedora
155-
__logging_is_rh_distro_fedora: "{{ ansible_distribution in __logging_rh_distros_fedora }}"
164+
__logging_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __logging_rh_distros_fedora }}"
156165
# END - DO NOT EDIT THIS BLOCK - rh distros variables

roles/rsyslog/tasks/main_core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- name: Reset original confs - logging package is absent
2525
# we can't do this with "package", dnf5 does not remove reverse
2626
# dependencies (such as rsyslog-gnutls) any more
27-
command: "{{ ansible_pkg_mgr }} remove -y {{ __rsyslog_only_packages | join(' ') }}"
27+
command: "{{ ansible_facts['pkg_mgr'] }} remove -y {{ __rsyslog_only_packages | join(' ') }}"
2828
# we know it's a change here, as we just rpm -V'ed it above
2929
changed_when: true
3030
register: __rsyslog_erased

roles/rsyslog/templates/input_ovirt.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ if $syslogtag == "{{ __rsyslog_input.name }}" then {
5454
set $!service = $syslogtag;
5555
set $!message = $.ovirt!message;
5656
set $!level = $.ovirt!level;
57-
set $!hostname = '{{ ansible_fqdn }}';
57+
set $!hostname = '{{ ansible_facts["fqdn"] }}';
5858
set $!ovirt!cluster_name = '{{ __ovirt_vds_cluster_name }}';
59-
set $!ipaddr4 = '{{ ansible_default_ipv4.address }}';
59+
set $!ipaddr4 = '{{ ansible_facts["default_ipv4"]["address"] }}';
6060
set $!ovirt!engine_fqdn = '{{ __ovirt_engine_fqdn }}';
6161
set $.input_type = "ovirt";
6262
set $!ovirt!class = $.ovirt!class;

roles/rsyslog/templates/input_relp.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
input(name="{{ __rsyslog_input.name }}"
22
type="imrelp"
33
port="{{ __rsyslog_input.port | d(20514) | int }}"
4-
{% if ansible_distribution in ['CentOS', 'RedHat'] and
5-
ansible_distribution_major_version is version('7', '>') %}
4+
{% if ansible_facts['distribution'] in ['CentOS', 'RedHat'] and
5+
ansible_facts['distribution_major_version'] is version('7', '>') %}
66
maxDataSize="{{ __rsyslog_input.max_data_size | d(logging_max_message_size) | int }}"
77
{% endif %}
88
{% if __rsyslog_input.tls | default(true) %}

tests/tests_combination.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
input_log_path: "{{ __test_inputfiles_dir }}/*.log"
5656
# Not supported on EL 7
5757
endmsg_regex: "{{ omit
58-
if ansible_distribution in ['CentOS', 'RedHat'] and
59-
ansible_distribution_major_version is version('7', '==')
58+
if ansible_facts['distribution'] in ['CentOS', 'RedHat'] and
59+
ansible_facts['distribution_major_version'] is version('7', '==')
6060
else 'xyz' }}"
6161
- name: basic_input
6262
type: basics

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/tests_relp.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@
190190
register: __result
191191
failed_when: __result.stdout != "1"
192192
when:
193-
- ansible_distribution in ['CentOS', 'RedHat']
194-
- ansible_distribution_major_version is version('7', '>')
193+
- ansible_facts['distribution'] in ['CentOS', 'RedHat']
194+
- ansible_facts['distribution_major_version'] is version('7', '>')
195195

196196
- name: Check preserveFQDN is on
197197
command: grep -c 'preserveFQDN="on"' {{ __test_relp_global }}

tests/vars/rh_distros_vars.yml

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

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

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

0 commit comments

Comments
 (0)