Skip to content

Commit 1412bc8

Browse files
authored
refactor: handle INJECT_FACTS_AS_VARS=false by using ansible_facts instead (#44)
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 bb70cbd commit 1412bc8

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
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/main.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
fail:
88
msg: >-
99
This role supports only on x86_64 architecture.
10-
You are running on {{ ansible_architecture }} architecture.
10+
You are running on {{ ansible_facts['architecture'] }} architecture.
1111
Let us know if you need the role to support it.
12-
when: ansible_architecture != 'x86_64'
12+
when: ansible_facts['architecture'] != 'x86_64'
1313

1414
- name: Fail if role installs openmpi without cuda toolkit
1515
fail:
@@ -61,20 +61,20 @@
6161

6262
- name: Ensure that the non-EUS RHUI Azure repository is not installed
6363
package:
64-
name: rhui-azure-rhel{{ ansible_distribution_major_version }}
64+
name: rhui-azure-rhel{{ ansible_facts['distribution_major_version'] }}
6565
state: absent
6666
use: "{{ (__hpc_server_is_ostree | d(false)) |
6767
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
6868

6969
- name: Enable the RHUI Azure EUS repository
7070
when: >-
71-
'rhui-microsoft-azure-rhel' + ansible_distribution_major_version
71+
'rhui-microsoft-azure-rhel' + ansible_facts['distribution_major_version']
7272
+ '-eus ' not in __hpc_dnf_repolist.stdout
7373
block:
7474
- name: Create a temp file for the EUS repository configuration
7575
tempfile:
7676
state: file
77-
prefix: rhel{{ ansible_distribution_major_version }}-eus
77+
prefix: rhel{{ ansible_facts['distribution_major_version'] }}-eus
7878
suffix: .config
7979
register: __hpc_euc_config
8080

@@ -89,13 +89,13 @@
8989
- name: Add EUS repository
9090
command: >-
9191
dnf --config {{ __hpc_euc_config.path }} install
92-
rhui-azure-rhel{{ ansible_distribution_major_version }}-eus
92+
rhui-azure-rhel{{ ansible_facts['distribution_major_version'] }}-eus
9393
--assumeyes
9494
changed_when: true
9595

9696
- name: Lock the RHEL minor release to the current minor release
9797
copy:
98-
content: "{{ ansible_distribution_version }}"
98+
content: "{{ ansible_facts['distribution_version'] }}"
9999
dest: /etc/dnf/vars/releasever
100100
mode: "0644"
101101
owner: root
@@ -225,7 +225,7 @@
225225
- name: Install NVidia driver
226226
# Note that currently the role supports only Microsoft Azure
227227
# When we add more cloud providers, we need to update this condition
228-
when: ansible_system_vendor == "Microsoft Corporation"
228+
when: ansible_facts["system_vendor"] == "Microsoft Corporation"
229229
block:
230230
- name: Get list of dnf modules
231231
command: dnf module list
@@ -274,7 +274,7 @@
274274

275275
- name: Install CUDA driver and enable nvidia-persistenced.service
276276
when:
277-
- ansible_system_vendor == "Microsoft Corporation"
277+
- ansible_facts["system_vendor"] == "Microsoft Corporation"
278278
- hpc_install_cuda_driver
279279
block:
280280
- name: Install CUDA driver
@@ -294,7 +294,7 @@
294294
- name: Install CUDA Toolkit and lock version of its packages
295295
when:
296296
- hpc_install_cuda_toolkit
297-
- ansible_system_vendor == "Microsoft Corporation"
297+
- ansible_facts["system_vendor"] == "Microsoft Corporation"
298298
block:
299299
- name: Install CUDA Toolkit
300300
package:
@@ -449,7 +449,7 @@
449449
./configure --prefix={{ __hpc_pmix_path }}
450450
--enable-pmix-binaries
451451
--disable-dependency-tracking
452-
- make -j {{ ansible_processor_nproc }}
452+
- make -j {{ ansible_facts["processor_nproc"] }}
453453
- make install
454454

455455
- name: Ensure PMIx modulefile directory exists
@@ -638,7 +638,7 @@
638638
--enable-prte-prefix-by-default
639639
--with-platform=contrib/platform/mellanox/optimized
640640
--with-cuda={{ __hpc_cuda_path }}
641-
- make -j {{ ansible_processor_nproc }}
641+
- make -j {{ ansible_facts["processor_nproc"] }}
642642
- make install
643643

644644
- name: Remove extracted tarball

templates/rhel-ver-eus.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[rhui-microsoft-azure-rhel{{ ansible_distribution_major_version }}]
2-
name=Microsoft Azure RPMs for Red Hat Enterprise Linux {{ ansible_distribution_major_version }} (rhel{{ ansible_distribution_major_version }}-eus)
3-
baseurl=https://rhui4-1.microsoft.com/pulp/repos/unprotected/microsoft-azure-rhel{{ ansible_distribution_major_version }}-eus
1+
[rhui-microsoft-azure-rhel{{ ansible_facts['distribution_major_version'] }}]
2+
name=Microsoft Azure RPMs for Red Hat Enterprise Linux {{ ansible_facts['distribution_major_version'] }} (rhel{{ ansible_facts['distribution_major_version'] }}-eus)
3+
baseurl=https://rhui4-1.microsoft.com/pulp/repos/unprotected/microsoft-azure-rhel{{ ansible_facts['distribution_major_version'] }}-eus
44
enabled=1
55
gpgcheck=1
66
sslverify=1

tests/tasks/skip_unsupported_archs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
when: '"architecture" not in ansible_facts.keys() | list'
77

88
- name: Skip unsupported architectures
9-
when: ansible_architecture != 'x86_64'
9+
when: ansible_facts['architecture'] != 'x86_64'
1010
meta: end_host

tests/tests_azure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
tasks:
1111
- name: End if not running on Azure
1212
meta: end_play
13-
when: ansible_system_vendor != "Microsoft Corporation"
13+
when: ansible_facts['system_vendor'] != "Microsoft Corporation"
1414

1515
- name: Run the role
1616
include_role:

tests/tests_include_vars_from_parent.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
# create all variants like CentOS, CentOS_8.1, CentOS-8.1,
3636
# CentOS-8, CentOS-8.1
3737
# more formally:
38-
# {{ ansible_distribution }}-{{ ansible_distribution_version }}
39-
# {{ ansible_distribution }}-{{ ansible_distribution_major_version }}
40-
# {{ ansible_distribution }}
41-
# {{ ansible_os_family }}
38+
# {{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}
39+
# {{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}
40+
# {{ ansible_facts['distribution'] }}
41+
# {{ ansible_facts['os_family'] }}
4242
# and the same for _ as separator.
4343
varfiles: "{{ [facts['distribution']] | product(separators) |
4444
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 @@ __hpc_rh_distros:
1414
__hpc_rh_distros_fedora: "{{ __hpc_rh_distros + ['Fedora'] }}"
1515

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

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

vars/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ __hpc_required_facts:
66
- distribution_major_version
77
- distribution_version
88
- os_family
9-
# required for ansible_system_vendor
9+
# required for ansible_facts["system_vendor"]
1010
- devices
11-
# required for ansible_processor_nproc
11+
# required for ansible_facts["processor_nproc"]
1212
- processor
1313
# the subsets of ansible_facts that need to be gathered in case any of the
1414
# facts in required_facts is missing; see the documentation of
@@ -87,8 +87,8 @@ __hpc_rh_distros:
8787
__hpc_rh_distros_fedora: "{{ __hpc_rh_distros + ['Fedora'] }}"
8888

8989
# Use this in conditionals to check if distro is Red Hat or clone
90-
__hpc_is_rh_distro: "{{ ansible_distribution in __hpc_rh_distros }}"
90+
__hpc_is_rh_distro: "{{ ansible_facts['distribution'] in __hpc_rh_distros }}"
9191

9292
# Use this in conditionals to check if distro is Red Hat or clone, or Fedora
93-
__hpc_is_rh_distro_fedora: "{{ ansible_distribution in __hpc_rh_distros_fedora }}"
93+
__hpc_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __hpc_rh_distros_fedora }}"
9494
# END - DO NOT EDIT THIS BLOCK - rh distros variables

0 commit comments

Comments
 (0)