From 6db6272497b09d0a279053d9f7431cf597037a97 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Wed, 7 Jan 2026 15:17:41 -0700 Subject: [PATCH] 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 --- README-ostree.md | 4 ++-- templates/postgresql-internal.conf.j2 | 4 ++-- tests/tasks/install_and_check.yml | 4 ++-- tests/tests_certificate.yml | 3 ++- tests/tests_custom_certificate.yml | 3 ++- tests/tests_include_vars_from_parent.yml | 8 ++++---- tests/vars/rh_distros_vars.yml | 4 ++-- vars/main.yml | 8 ++++---- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/README-ostree.md b/README-ostree.md index a9f0185b96..af5bcdcdf4 100644 --- a/README-ostree.md +++ b/README-ostree.md @@ -20,8 +20,8 @@ Usage: .ostree/get_ostree_data.sh packages runtime DISTRO-VERSION FORMAT ``` -`DISTRO-VERSION` is in the format that Ansible uses for `ansible_distribution` -and `ansible_distribution_version` - for example, `Fedora-38`, `CentOS-8`, +`DISTRO-VERSION` is in the format that Ansible uses for `ansible_facts["distribution"]` +and `ansible_facts["distribution_version"]` - for example, `Fedora-38`, `CentOS-8`, `RedHat-9.4` `FORMAT` is one of `toml`, `json`, `yaml`, `raw` diff --git a/templates/postgresql-internal.conf.j2 b/templates/postgresql-internal.conf.j2 index 153e9a4c83..ff4e629912 100644 --- a/templates/postgresql-internal.conf.j2 +++ b/templates/postgresql-internal.conf.j2 @@ -2,8 +2,8 @@ {{ "system_role:postgresql" | comment(prefix="", postfix="") }} {% if postgresql_server_tuning %} -shared_buffers = {{ (ansible_memory_mb.real.total / 4) | int | abs }}MB -effective_cache_size = {{ (ansible_memory_mb.real.total / 2) | int | abs }}MB +shared_buffers = {{ (ansible_facts.memory_mb.real.total / 4) | int | abs }}MB +effective_cache_size = {{ (ansible_facts.memory_mb.real.total / 2) | int | abs }}MB {% endif %} {% if postgresql_ssl_enable %} ssl = on diff --git a/tests/tasks/install_and_check.yml b/tests/tasks/install_and_check.yml index a720ba8c63..1c34a7ef34 100644 --- a/tests/tasks/install_and_check.yml +++ b/tests/tasks/install_and_check.yml @@ -56,7 +56,7 @@ - name: Test - server tuning is used - shared buffers assert: that: > - (ansible_memory_mb.real.total/4) | int | abs | string + (ansible_facts.memory_mb.real.total/4) | int | abs | string in result.stdout when: - __test_check_unix_socket | d(true) @@ -79,7 +79,7 @@ - name: Test - server tuning is used - effective cache size assert: that: > - (ansible_memory_mb.real.total/2) | int | abs | string + (ansible_facts.memory_mb.real.total/2) | int | abs | string in result.stdout when: - __test_check_unix_socket | d(true) diff --git a/tests/tests_certificate.yml b/tests/tests_certificate.yml index 2527100f0c..bfbe005ba6 100644 --- a/tests/tests_certificate.yml +++ b/tests/tests_certificate.yml @@ -38,7 +38,8 @@ - name: Check output of psql assert: that: >- - "SSL connection" in result.stdout + "SSL connection" in result.stdout or + "SSL Connection" in result.stdout always: - name: Stop tracking certificate command: getcert stop-tracking -f /etc/pki/tls/certs/test_crt.crt diff --git a/tests/tests_custom_certificate.yml b/tests/tests_custom_certificate.yml index 493db463e1..f21f1df503 100644 --- a/tests/tests_custom_certificate.yml +++ b/tests/tests_custom_certificate.yml @@ -45,7 +45,8 @@ - name: Check output of psql assert: that: >- - "SSL connection" in result.stdout + "SSL connection" in result.stdout or + "SSL Connection" in result.stdout always: - name: Clean up include_tasks: tasks/clean_instance.yml diff --git a/tests/tests_include_vars_from_parent.yml b/tests/tests_include_vars_from_parent.yml index e339e04231..7f282de72c 100644 --- a/tests/tests_include_vars_from_parent.yml +++ b/tests/tests_include_vars_from_parent.yml @@ -32,10 +32,10 @@ # create all variants like CentOS, CentOS_8.1, CentOS-8.1, # CentOS-8, CentOS-8.1 # more formally: - # {{ ansible_distribution }}-{{ ansible_distribution_version }} - # {{ ansible_distribution }}-{{ ansible_distribution_major_version }} - # {{ ansible_distribution }} - # {{ ansible_os_family }} + # {{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }} + # {{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }} + # {{ ansible_facts['distribution'] }} + # {{ ansible_facts['os_family'] }} # and the same for _ as separator. varfiles: "{{ [facts['distribution']] | product(separators) | map('join') | product(versions) | map('join') | list + diff --git a/tests/vars/rh_distros_vars.yml b/tests/vars/rh_distros_vars.yml index a2252eaff8..96c993c5ce 100644 --- a/tests/vars/rh_distros_vars.yml +++ b/tests/vars/rh_distros_vars.yml @@ -14,7 +14,7 @@ __postgresql_rh_distros: __postgresql_rh_distros_fedora: "{{ __postgresql_rh_distros + ['Fedora'] }}" # Use this in conditionals to check if distro is Red Hat or clone -__postgresql_is_rh_distro: "{{ ansible_distribution in __postgresql_rh_distros }}" +__postgresql_is_rh_distro: "{{ ansible_facts['distribution'] in __postgresql_rh_distros }}" # Use this in conditionals to check if distro is Red Hat or clone, or Fedora -__postgresql_is_rh_distro_fedora: "{{ ansible_distribution in __postgresql_rh_distros_fedora }}" +__postgresql_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __postgresql_rh_distros_fedora }}" diff --git a/vars/main.yml b/vars/main.yml index 6fbffa88be..c59c09a0ef 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -23,10 +23,10 @@ __postgresql_required_facts: - distribution_major_version - distribution_version - os_family - - ansible_memory_mb + - memory_mb # these facts cannot be used as a gather_subset -__postgresql_no_subset_facts: [ansible_memory_mb] +__postgresql_no_subset_facts: [memory_mb] # the subsets of ansible_facts that need to be gathered in case any of the # facts in required_facts is missing; see the documentation of @@ -46,8 +46,8 @@ __postgresql_rh_distros: __postgresql_rh_distros_fedora: "{{ __postgresql_rh_distros + ['Fedora'] }}" # Use this in conditionals to check if distro is Red Hat or clone -__postgresql_is_rh_distro: "{{ ansible_distribution in __postgresql_rh_distros }}" +__postgresql_is_rh_distro: "{{ ansible_facts['distribution'] in __postgresql_rh_distros }}" # Use this in conditionals to check if distro is Red Hat or clone, or Fedora -__postgresql_is_rh_distro_fedora: "{{ ansible_distribution in __postgresql_rh_distros_fedora }}" +__postgresql_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __postgresql_rh_distros_fedora }}" # END - DO NOT EDIT THIS BLOCK - rh distros variables