Skip to content

Commit 2081992

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 7d5b68b commit 2081992

8 files changed

Lines changed: 20 additions & 18 deletions

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`

templates/postgresql-internal.conf.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{{ "system_role:postgresql" | comment(prefix="", postfix="") }}
33

44
{% if postgresql_server_tuning %}
5-
shared_buffers = {{ (ansible_memory_mb.real.total / 4) | int | abs }}MB
6-
effective_cache_size = {{ (ansible_memory_mb.real.total / 2) | int | abs }}MB
5+
shared_buffers = {{ (ansible_facts.memory_mb.real.total / 4) | int | abs }}MB
6+
effective_cache_size = {{ (ansible_facts.memory_mb.real.total / 2) | int | abs }}MB
77
{% endif %}
88
{% if postgresql_ssl_enable %}
99
ssl = on

tests/tasks/install_and_check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
- name: Test - server tuning is used - shared buffers
5757
assert:
5858
that: >
59-
(ansible_memory_mb.real.total/4) | int | abs | string
59+
(ansible_facts.memory_mb.real.total/4) | int | abs | string
6060
in result.stdout
6161
when:
6262
- __test_check_unix_socket | d(true)
@@ -79,7 +79,7 @@
7979
- name: Test - server tuning is used - effective cache size
8080
assert:
8181
that: >
82-
(ansible_memory_mb.real.total/2) | int | abs | string
82+
(ansible_facts.memory_mb.real.total/2) | int | abs | string
8383
in result.stdout
8484
when:
8585
- __test_check_unix_socket | d(true)

tests/tests_certificate.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
- name: Check output of psql
3939
assert:
4040
that: >-
41-
"SSL connection" in result.stdout
41+
"SSL connection" in result.stdout or
42+
"SSL Connection" in result.stdout
4243
always:
4344
- name: Stop tracking certificate
4445
command: getcert stop-tracking -f /etc/pki/tls/certs/test_crt.crt

tests/tests_custom_certificate.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
- name: Check output of psql
4646
assert:
4747
that: >-
48-
"SSL connection" in result.stdout
48+
"SSL connection" in result.stdout or
49+
"SSL Connection" in result.stdout
4950
always:
5051
- name: Clean up
5152
include_tasks: tasks/clean_instance.yml

tests/tests_include_vars_from_parent.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
# create all variants like CentOS, CentOS_8.1, CentOS-8.1,
3333
# CentOS-8, CentOS-8.1
3434
# more formally:
35-
# {{ ansible_distribution }}-{{ ansible_distribution_version }}
36-
# {{ ansible_distribution }}-{{ ansible_distribution_major_version }}
37-
# {{ ansible_distribution }}
38-
# {{ ansible_os_family }}
35+
# {{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}
36+
# {{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}
37+
# {{ ansible_facts['distribution'] }}
38+
# {{ ansible_facts['os_family'] }}
3939
# and the same for _ as separator.
4040
varfiles: "{{ [facts['distribution']] | product(separators) |
4141
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 @@ __postgresql_rh_distros:
1414
__postgresql_rh_distros_fedora: "{{ __postgresql_rh_distros + ['Fedora'] }}"
1515

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

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

vars/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ __postgresql_required_facts:
2323
- distribution_major_version
2424
- distribution_version
2525
- os_family
26-
- ansible_memory_mb
26+
- memory_mb
2727

2828
# these facts cannot be used as a gather_subset
29-
__postgresql_no_subset_facts: [ansible_memory_mb]
29+
__postgresql_no_subset_facts: [memory_mb]
3030

3131
# the subsets of ansible_facts that need to be gathered in case any of the
3232
# facts in required_facts is missing; see the documentation of
@@ -46,8 +46,8 @@ __postgresql_rh_distros:
4646
__postgresql_rh_distros_fedora: "{{ __postgresql_rh_distros + ['Fedora'] }}"
4747

4848
# Use this in conditionals to check if distro is Red Hat or clone
49-
__postgresql_is_rh_distro: "{{ ansible_distribution in __postgresql_rh_distros }}"
49+
__postgresql_is_rh_distro: "{{ ansible_facts['distribution'] in __postgresql_rh_distros }}"
5050

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

0 commit comments

Comments
 (0)