Skip to content

Commit 5b967aa

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 fefef33 commit 5b967aa

23 files changed

+74
-74
lines changed

tests/check_default_datasources.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
- bpftrace
1717
when:
1818
- __metrics_is_booted | bool
19-
- ansible_distribution in ['RedHat', 'CentOS']
20-
- ansible_distribution_major_version | int > 6
21-
- ansible_distribution_major_version | int < 10
19+
- ansible_facts['distribution'] in ['RedHat', 'CentOS']
20+
- ansible_facts['distribution_major_version'] | int > 6
21+
- ansible_facts['distribution_major_version'] | int < 10
2222

2323
- name: Check if grafana-pcp datasources are configured
2424
uri:
@@ -35,8 +35,8 @@
3535
- bpftrace
3636
when:
3737
- __metrics_is_booted | bool
38-
- (ansible_distribution in ['RedHat', 'CentOS'] and
39-
ansible_distribution_major_version | int >= 10) or
40-
ansible_distribution not in ['RedHat', 'CentOS']
38+
- (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
39+
ansible_facts['distribution_major_version'] | int >= 10) or
40+
ansible_facts['distribution'] not in ['RedHat', 'CentOS']
4141

4242
# yamllint enable rule:line-length

tests/check_firewall_selinux.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
# changed_when: false
2929
# when:
3030
# - metrics_query_service | d(false) | bool
31-
# - ansible_distribution not in ['RedHat', 'CentOS'] or
32-
# (ansible_distribution in ['RedHat', 'CentOS'] and
33-
# ansible_distribution_major_version | int >= 10)
31+
# - ansible_facts['distribution'] not in ['RedHat', 'CentOS'] or
32+
# (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
33+
# ansible_facts['distribution_major_version'] | int >= 10)
3434

3535
- name: "Check firewall service status for redis;
3636
metrics_manage_firewall is true"
@@ -40,9 +40,9 @@
4040
changed_when: false
4141
when:
4242
- metrics_query_service|d(false)|bool
43-
- ansible_distribution in ['RedHat', 'CentOS']
44-
- ansible_distribution_major_version | int > 6
45-
- ansible_distribution_major_version | int < 10
43+
- ansible_facts['distribution'] in ['RedHat', 'CentOS']
44+
- ansible_facts['distribution_major_version'] | int > 6
45+
- ansible_facts['distribution_major_version'] | int < 10
4646

4747
- name: "Check firewall port status for pmproxy;
4848
metrics_manage_firewall is true"
@@ -70,9 +70,9 @@
7070
changed_when: false
7171
when:
7272
- metrics_query_service | d(false) | bool
73-
- ansible_distribution not in ['RedHat', 'CentOS'] or
74-
(ansible_distribution in ['RedHat', 'CentOS'] and
75-
ansible_distribution_major_version | int >= 10)
73+
- ansible_facts['distribution'] not in ['RedHat', 'CentOS'] or
74+
(ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
75+
ansible_facts['distribution_major_version'] | int >= 10)
7676

7777
- name: Check associated selinux ports (metrics_manage_selinux is true)
7878
shell: |-

tests/check_keyserver.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
valkey-cli PING | grep PONG
77
changed_when: false
88
when:
9-
- (ansible_distribution in ['RedHat', 'CentOS'] and
10-
ansible_distribution_major_version | int >= 10) or
11-
ansible_distribution not in ['RedHat', 'CentOS']
9+
- (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
10+
ansible_facts['distribution_major_version'] | int >= 10) or
11+
ansible_facts['distribution'] not in ['RedHat', 'CentOS']
1212
- __metrics_is_booted | bool
1313

1414
- name: Check if Redis responds
@@ -17,7 +17,7 @@
1717
redis-cli PING | grep PONG
1818
changed_when: false
1919
when:
20-
- ansible_distribution in ['RedHat', 'CentOS']
21-
- ansible_distribution_major_version | int > 6
22-
- ansible_distribution_major_version | int < 10
20+
- ansible_facts['distribution'] in ['RedHat', 'CentOS']
21+
- ansible_facts['distribution_major_version'] | int > 6
22+
- ansible_facts['distribution_major_version'] | int < 10
2323
- __metrics_is_booted | bool

tests/check_pmie.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pmprobe -I pmcd.pmie.pmcd_host | grep '"primary"'
77
changed_when: false
88
when:
9-
- (ansible_distribution in ['RedHat', 'CentOS'] and
10-
ansible_distribution_major_version | int > 6) or
11-
ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']
9+
- (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
10+
ansible_facts['distribution_major_version'] | int > 6) or
11+
ansible_facts['distribution'] not in ['Fedora', 'RedHat', 'CentOS']
1212
- __metrics_is_booted | bool

tests/check_pmie_webhook.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
pmieconf -f /var/lib/pcp/config/pmie/config.default list global webhook_endpoint | grep '"example"'
2626
pmieconf -f /var/lib/pcp/config/pmie/config.default list global webhook_action | grep '"yes"'
2727
when:
28-
- (ansible_distribution in ['RedHat', 'CentOS'] and
28+
- (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
2929
(ansible_facts['distribution_version'] is version('9.3', '<'))) or
30-
ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']
30+
ansible_facts['distribution'] not in ['Fedora', 'RedHat', 'CentOS']
3131
- __metrics_is_booted | bool
3232

3333
# yamllint enable rule:line-length

tests/check_pmlogger.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
pmprobe -I pmcd.pmlogger.pmcd_host | grep '"primary"'
77
changed_when: false
88
when:
9-
- (ansible_distribution in ['RedHat', 'CentOS'] and
10-
ansible_distribution_major_version | int > 6) or
11-
ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']
9+
- (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
10+
ansible_facts['distribution_major_version'] | int > 6) or
11+
ansible_facts['distribution'] not in ['Fedora', 'RedHat', 'CentOS']
1212
- __metrics_is_booted | bool
1313

1414
- name: Check the ansible_managed header in the configuration file

tests/tests_bz1855539.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
pre_tasks:
1111
- name: Stop test
1212
meta: end_host
13-
when: (ansible_distribution in ['RedHat', 'CentOS'] and
14-
ansible_distribution_major_version | int < 7) or
15-
ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']
13+
when: (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
14+
ansible_facts['distribution_major_version'] | int < 7) or
15+
ansible_facts['distribution'] not in ['Fedora', 'RedHat', 'CentOS']
1616

1717
- name: Save state of services
1818
import_tasks: get_services_state.yml

tests/tests_bz1855544.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
pre_tasks:
1212
- name: Stop test
1313
meta: end_host
14-
when: (ansible_distribution in ['RedHat', 'CentOS'] and
15-
ansible_distribution_major_version | int < 8) or
16-
ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']
14+
when: (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
15+
ansible_facts['distribution_major_version'] | int < 8) or
16+
ansible_facts['distribution'] not in ['Fedora', 'RedHat', 'CentOS']
1717

1818
- name: Save state of services
1919
import_tasks: get_services_state.yml

tests/tests_verify_auth.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
pre_tasks:
1414
- name: Stop test
1515
meta: end_host
16-
when: (ansible_distribution in ['RedHat', 'CentOS'] and
17-
ansible_distribution_major_version | int < 8) or
18-
ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']
16+
when: (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
17+
ansible_facts['distribution_major_version'] | int < 8) or
18+
ansible_facts['distribution'] not in ['Fedora', 'RedHat', 'CentOS']
1919

2020
- name: Save state of services
2121
import_tasks: get_services_state.yml

tests/tests_verify_bpftrace.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
pre_tasks:
1515
- name: Stop test
1616
meta: end_host
17-
when: (ansible_distribution in ['RedHat', 'CentOS'] and
18-
ansible_distribution_major_version | int < 8) or
19-
ansible_distribution not in ['Fedora', 'RedHat', 'CentOS']
17+
when: (ansible_facts['distribution'] in ['RedHat', 'CentOS'] and
18+
ansible_facts['distribution_major_version'] | int < 8) or
19+
ansible_facts['distribution'] not in ['Fedora', 'RedHat', 'CentOS']
2020

2121
- name: Save state of services
2222
import_tasks: get_services_state.yml

0 commit comments

Comments
 (0)