Skip to content

Commit bbf8f83

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 6580d92 commit bbf8f83

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

tasks/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@
110110
when:
111111
- ad_integration_manage_crypto_policies | bool
112112
# Fedora and RHEL8+
113-
- (ansible_distribution == "Fedora" or
114-
(ansible_distribution in __ad_integration_rh_distros and
115-
ansible_distribution_version is version('8', '>=')))
113+
- (ansible_facts['distribution'] == "Fedora" or
114+
(ansible_facts['distribution'] in __ad_integration_rh_distros and
115+
ansible_facts['distribution_version'] is version('8', '>=')))
116116

117117
## RHEL9 uses the AD-SUPPORT-LEGACY policy for RC4,
118118
## otherwise AD-SUPPORT allows it
@@ -123,8 +123,8 @@
123123
crypto_policies_policy: "DEFAULT:AD-SUPPORT-LEGACY"
124124
when:
125125
- ad_integration_allow_rc4_crypto | bool
126-
- ansible_distribution in __ad_integration_rh_distros
127-
- ansible_distribution_version is version('9', '>=')
126+
- ansible_facts['distribution'] in __ad_integration_rh_distros
127+
- ansible_facts['distribution_version'] is version('9', '>=')
128128

129129
- name: Grab existing domain settings from sssd.conf if we want to merge
130130
when: ad_integration_sssd_merge_duplicate_sections | bool
@@ -347,8 +347,8 @@
347347
# For dynamic dns to work the machine either needs fqdn in hostname
348348
# or ad_hostname needs to be defined.
349349
- key: ad_hostname
350-
value: "{{ ansible_hostname + '.' + ad_integration_realm | lower
351-
| string if '.' not in ansible_hostname else '' }}"
350+
value: "{{ ansible_facts['hostname'] + '.' + ad_integration_realm | lower
351+
| string if '.' not in ansible_facts['hostname'] else '' }}"
352352
when:
353353
- ad_dyndns_update | bool
354354
- item.value is not none

tests/templates/fake_realm.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!{{ ansible_python.executable }}
1+
#!{{ ansible_facts['python']['executable'] }}
22
import argparse
33
import os
44
import sys

tests/tests_dyndns.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@
123123
# in my situation my ansible control host is on a different network and
124124
# DNS than the VMs I am testing against.
125125
- name: Get IP for host's FQDN
126-
command: dig +short {{ ansible_fqdn }} A
126+
command: dig +short {{ ansible_facts['fqdn'] }} A
127127
register: dig_hostname
128128
changed_when: false
129129
failed_when: false
130130

131131
- name: Get hostname for host's IP address
132-
command: dig +short -x {{ ansible_default_ipv4.address }} PTR
132+
command: dig +short -x {{ ansible_facts['default_ipv4']['address'] }} PTR
133133
register: dig_ip
134134
changed_when: false
135135
failed_when: false
@@ -138,9 +138,9 @@
138138
assert:
139139
that:
140140
- "'{{ dig_hostname.stdout }}' ==
141-
'{{ ansible_default_ipv4.address }}'"
142-
- "'{{ dig_ip.stdout }}' == '{{ ansible_fqdn }}.'"
143-
when: ansible_default_ipv4.address is defined
141+
'{{ ansible_facts['default_ipv4']['address'] }}'"
142+
- "'{{ dig_ip.stdout }}' == '{{ ansible_facts['fqdn'] }}.'"
143+
when: ansible_facts['default_ipv4']['address'] is defined
144144

145145
always:
146146
- name: Cleanup fake realm

tests/tests_full_integration_dyndns.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@
7070
- name: Debug dyndns settings
7171
debug:
7272
msg: >-
73-
Interface {{ _ad_dyndns_iface | default(ansible_default_ipv4.interface) }} and server
73+
Interface {{ _ad_dyndns_iface | default(ansible_facts['default_ipv4']['interface']) }} and server
7474
: {{ hostvars[groups['ad'][0]].ansible_host }}
7575
- name: Run the system role with proper config
7676
include_role:
7777
name: linux-system-roles.ad_integration
7878
public: true
7979
vars:
8080
ad_dyndns_server: "{{ hostvars[groups['ad'][0]].ansible_host }}"
81-
ad_dyndns_iface: "{{ _ad_dyndns_iface | default(ansible_default_ipv4.interface) }}"
81+
ad_dyndns_iface: "{{ _ad_dyndns_iface | default(ansible_facts['default_ipv4']['interface']) }}"
8282
ad_dyndns_auth: "none"
8383
ad_dyndns_update: true
8484
ad_dyndns_refresh_interval: 60
@@ -108,13 +108,13 @@
108108
changed_when: false
109109
- name: Get IP for host's FQDN
110110
command: >-
111-
dig +short {{ ansible_fqdn }}.{{
111+
dig +short {{ ansible_facts['fqdn'] }}.{{
112112
hostvars[groups['client'][0]].ad_integration_realm }} A
113113
register: dig_hostname
114114
changed_when: false
115115
failed_when: false
116116
- name: Get hostname for host's IP address
117-
command: "dig +short -x {{ ansible_default_ipv4.address }} PTR"
117+
command: "dig +short -x {{ ansible_facts['default_ipv4']['address'] }} PTR"
118118
register: dig_ip
119119
changed_when: false
120120
failed_when: false

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

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

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

vars/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ __ad_integration_rh_distros:
4444
__ad_integration_rh_distros_fedora: "{{ __ad_integration_rh_distros + ['Fedora'] }}"
4545

4646
# Use this in conditionals to check if distro is Red Hat or clone
47-
__ad_integration_is_rh_distro: "{{ ansible_distribution in __ad_integration_rh_distros }}"
47+
__ad_integration_is_rh_distro: "{{ ansible_facts['distribution'] in __ad_integration_rh_distros }}"
4848

4949
# Use this in conditionals to check if distro is Red Hat or clone, or Fedora
50-
__ad_integration_is_rh_distro_fedora: "{{ ansible_distribution in __ad_integration_rh_distros_fedora }}"
50+
__ad_integration_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __ad_integration_rh_distros_fedora }}"
5151
# END - DO NOT EDIT THIS BLOCK - rh distros variables

0 commit comments

Comments
 (0)