Skip to content

Commit 7b42c32

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 <[email protected]>
1 parent 2244006 commit 7b42c32

21 files changed

+33
-32
lines changed

tasks/enable_copr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
- name: Get list of COPRs
33
shell: |
44
set -euo pipefail
5-
{{ ansible_pkg_mgr }} repolist | \
5+
{{ ansible_facts['pkg_mgr'] }} repolist | \
66
grep -c `echo {{ repo.repository }} | tr / :` || true
77
register: copr_present
88
changed_when: false
99

1010
- name: Enable COPRs
1111
command:
12-
cmd: "{{ ansible_pkg_mgr }} -y copr enable {{ repo.repository }}"
12+
cmd: "{{ ansible_facts['pkg_mgr'] }} -y copr enable {{ repo.repository }}"
1313
when: copr_present.stdout == "0"
1414
changed_when: true

tests/test-verify-pool-members.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
- name: Set test variables
33
set_fact:
4-
_storage_test_pool_pvs_lvm: "{{ ansible_lvm.pvs | dict2items |
4+
_storage_test_pool_pvs_lvm: "{{ ansible_facts['lvm'].pvs | dict2items |
55
selectattr('value.vg', 'match', '^' ~ storage_test_pool.name ~ '$') |
66
map(attribute='key') | list }}"
77
_storage_test_expected_pv_count: "{{ 0
@@ -79,7 +79,7 @@
7979
scripts/does_library_support.py
8080
blivet.formats.lvmpv.LVMPhysicalVolume.grow_to_fill
8181
args:
82-
executable: "{{ ansible_python.executable }}"
82+
executable: "{{ ansible_facts['python'].executable }}"
8383
register: grow_supported
8484
changed_when: false
8585
failed_when: grow_supported.rc not in [0, 1]

tests/test-verify-volume-size.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
- name: Get the size of parent/pool device
3333
bsize:
34-
size: "{{ ansible_lvm.vgs[storage_test_pool.name].size_g + 'G' }}"
34+
size: "{{ ansible_facts['lvm'].vgs[storage_test_pool.name].size_g + 'G' }}"
3535
register: storage_test_pool_size
3636
when:
3737
- _storage_test_volume_present | bool

tests/tests_change_disk_fs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
mount_location: '/opt/test'
88
volume_size: '5g'
99
fs_type_after: "{{ 'ext3'
10-
if (ansible_distribution == 'RedHat' and
11-
ansible_distribution_major_version == '6')
10+
if (ansible_facts['distribution'] == 'RedHat' and
11+
ansible_facts['distribution_major_version'] == '6')
1212
else 'ext4' }}"
1313
tasks:
1414
- name: Run the role

tests/tests_change_fs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
storage_safe_mode: false
77
mount_location: '/opt/test1'
88
volume_size: '5g'
9-
fs_after: "{{ (ansible_distribution == 'RedHat' and
10-
ansible_distribution_major_version == '6') |
9+
fs_after: "{{ (ansible_facts['distribution'] == 'RedHat' and
10+
ansible_facts['distribution_major_version'] == '6') |
1111
ternary('ext4', 'xfs') }}"
1212
tags:
1313
- tests::lvm

tests/tests_change_fs_use_partitions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
mount_location: '/opt/test1'
99
volume_size: '5g'
1010
fs_type_after: "{{ 'ext3'
11-
if (ansible_distribution == 'RedHat' and
12-
ansible_distribution_major_version == '6')
11+
if (ansible_facts['distribution'] == 'RedHat' and
12+
ansible_facts['distribution_major_version'] == '6')
1313
else 'ext4' }}"
1414
tags:
1515
- tests::lvm

tests/tests_create_lv_size_equal_to_vg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
mount_location: '/opt/test1'
88
volume_group_size: '10g'
99
lv_size: '10g'
10-
unused_disk_subfact: '{{ ansible_devices[unused_disks[0]] }}'
10+
unused_disk_subfact: '{{ ansible_facts["devices"][unused_disks[0]] }}'
1111
disk_size: '{{ unused_disk_subfact.sectors | int * 512 }}'
1212
tags:
1313
- tests::lvm

tests/tests_create_thinp_then_remove.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
mount_location3: '/opt/test3'
1111
volume1_size: '3g'
1212
volume2_size: '4g'
13-
fs_after: "{{ (ansible_distribution == 'RedHat' and
14-
ansible_distribution_major_version == '6') |
13+
fs_after: "{{ (ansible_facts['distribution'] == 'RedHat' and
14+
ansible_facts['distribution_major_version'] == '6') |
1515
ternary('ext4', 'xfs') }}"
1616

1717
tasks:

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_lvm_errors.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
invalid_disks:
1212
- '/non/existent/disk'
1313
invalid_size: 'xyz GiB'
14-
unused_disk_subfact: '{{ ansible_devices[unused_disks[0]] }}'
14+
unused_disk_subfact: '{{ ansible_facts["devices"][unused_disks[0]] }}'
1515
tags:
1616
- tests::lvm
1717
tasks:

0 commit comments

Comments
 (0)