From a59d295c6bd00e9ed84907c80bc2d2f756399f2e Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Wed, 7 Jan 2026 17:20:46 -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 ++-- tests/tests_include_vars_from_parent.yml | 10 +++++----- tests/vars/rh_distros_vars.yml | 4 ++-- vars/main.yml | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README-ostree.md b/README-ostree.md index a9f0185b..af5bcdcd 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/tests/tests_include_vars_from_parent.yml b/tests/tests_include_vars_from_parent.yml index fcdea4b4..635ab9cb 100644 --- a/tests/tests_include_vars_from_parent.yml +++ b/tests/tests_include_vars_from_parent.yml @@ -40,11 +40,11 @@ # 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 98c4a0d7..d1b3124f 100644 --- a/tests/vars/rh_distros_vars.yml +++ b/tests/vars/rh_distros_vars.yml @@ -14,7 +14,7 @@ __snapshot_rh_distros: __snapshot_rh_distros_fedora: "{{ __snapshot_rh_distros + ['Fedora'] }}" # Use this in conditionals to check if distro is Red Hat or clone -__snapshot_is_rh_distro: "{{ ansible_distribution in __snapshot_rh_distros }}" +__snapshot_is_rh_distro: "{{ ansible_facts['distribution'] in __snapshot_rh_distros }}" # Use this in conditionals to check if distro is Red Hat or clone, or Fedora -__snapshot_is_rh_distro_fedora: "{{ ansible_distribution in __snapshot_rh_distros_fedora }}" +__snapshot_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __snapshot_rh_distros_fedora }}" diff --git a/vars/main.yml b/vars/main.yml index 1f0cda0a..a71f0731 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -4,14 +4,14 @@ __snapshot_base_packages_7_8: ["lvm2", "util-linux"] __snapshot_base_packages_other: ["lvm2", "util-linux-core"] __snapshot_base_packages: "{{ __snapshot_base_packages_7_8 if (__snapshot_is_rh_distro and - ansible_distribution_version is version('9', '<')) + ansible_facts['distribution_version'] is version('9', '<')) else __snapshot_base_packages_other }}" __snapshot_extra_packages: ["boom-boot", "snapm"] __snapshot_packages: "{{ __snapshot_base_packages + __snapshot_extra_packages if ((__snapshot_is_rh_distro and - ansible_distribution_version is version('9.6', '>=')) or - (ansible_distribution == 'Fedora' and - ansible_distribution_version is version('41', '>='))) + ansible_facts['distribution_version'] is version('9.6', '>=')) or + (ansible_facts['distribution'] == 'Fedora' and + ansible_facts['distribution_version'] is version('41', '>='))) else __snapshot_base_packages }}" __snapshot_services: [] # python to use on managed nodes for snapshot.py @@ -40,8 +40,8 @@ __snapshot_rh_distros: __snapshot_rh_distros_fedora: "{{ __snapshot_rh_distros + ['Fedora'] }}" # Use this in conditionals to check if distro is Red Hat or clone -__snapshot_is_rh_distro: "{{ ansible_distribution in __snapshot_rh_distros }}" +__snapshot_is_rh_distro: "{{ ansible_facts['distribution'] in __snapshot_rh_distros }}" # Use this in conditionals to check if distro is Red Hat or clone, or Fedora -__snapshot_is_rh_distro_fedora: "{{ ansible_distribution in __snapshot_rh_distros_fedora }}" +__snapshot_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __snapshot_rh_distros_fedora }}" # END - DO NOT EDIT THIS BLOCK - rh distros variables