From e2c4cd43bb869a2fe552a93fb1e49b1edf27c7d5 Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Mon, 1 Mar 2021 13:25:13 +0000 Subject: [PATCH] Use ansible_facts[] instead of fact variables in tests See https://github.com/ansible/ansible/issues/73654 Change-Id: I7e27477d4fb1292aa5d79adcf6cb33eaa31da035 --- tests/bootstrap-aio.yml | 10 ++++++---- tests/roles/bootstrap-host/defaults/main.yml | 12 ++++++------ .../bootstrap-host/tasks/check-requirements.yml | 17 ++++++++--------- .../bootstrap-host/tasks/install_packages.yml | 2 +- tests/roles/bootstrap-host/tasks/main.yml | 12 ++++++------ .../bootstrap-host/tasks/prepare_aio_config.yml | 6 +++--- .../bootstrap-host/tasks/prepare_data_disk.yml | 2 +- .../tasks/prepare_loopback_zfs.yml | 2 +- .../bootstrap-host/tasks/prepare_networking.yml | 4 ++-- .../bootstrap-host/tasks/prepare_squid.yml | 2 +- .../templates/user_variables.aio.yml.j2 | 4 ++-- 11 files changed, 37 insertions(+), 36 deletions(-) diff --git a/tests/bootstrap-aio.yml b/tests/bootstrap-aio.yml index 8a87660f8e..5bee5b7c8e 100644 --- a/tests/bootstrap-aio.yml +++ b/tests/bootstrap-aio.yml @@ -60,7 +60,7 @@ PrintLastLog: no TCPKeepAlive: yes AcceptEnv: "LANG LC_*" - Subsystem: "{{ sftp_subsystem[ansible_pkg_mgr] }}" + Subsystem: "{{ sftp_subsystem[ansible_facts['pkg_mgr']] }}" UsePAM: yes UseDNS: no X11Forwarding: no @@ -81,8 +81,10 @@ - name: Check that new network interfaces are up assert: that: - - ansible_eth12['active'] | bool - - ansible_eth13['active'] | bool - - ansible_eth14['active'] | bool + - ansible_facts['eth12']['active'] | bool + - ansible_facts['eth13']['active'] | bool + - ansible_facts['eth14']['active'] | bool when: - (bootstrap_host_container_tech | default('unknown')) != 'nspawn' + - name: Clear facts + meta: clear_facts diff --git a/tests/roles/bootstrap-host/defaults/main.yml b/tests/roles/bootstrap-host/defaults/main.yml index 1d307c932b..2fdb6de4bd 100644 --- a/tests/roles/bootstrap-host/defaults/main.yml +++ b/tests/roles/bootstrap-host/defaults/main.yml @@ -105,7 +105,7 @@ vlan_range: "172.29.248" netmask: "255.255.252.0" # # NICs -bootstrap_host_public_interface: "{{ ansible_default_ipv4.interface }}" +bootstrap_host_public_interface: "{{ ansible_facts['default_ipv4']['interface'] }}" # # Utility paths bootstrap_host_network_utils: @@ -126,9 +126,9 @@ bootstrap_host_network_utils: ethtool: /sbin/ethtool ip: /sbin/ip # -bootstrap_host_iptables_path: "{{ bootstrap_host_network_utils[ansible_pkg_mgr]['iptables'] }}" -bootstrap_host_ethtool_path: "{{ bootstrap_host_network_utils[ansible_pkg_mgr]['ethtool'] }}" -bootstrap_host_ip_path: "{{ bootstrap_host_network_utils[ansible_pkg_mgr]['ip'] }}" +bootstrap_host_iptables_path: "{{ bootstrap_host_network_utils[ansible_facts['pkg_mgr']]['iptables'] }}" +bootstrap_host_ethtool_path: "{{ bootstrap_host_network_utils[ansible_facts['pkg_mgr']]['ethtool'] }}" +bootstrap_host_ip_path: "{{ bootstrap_host_network_utils[ansible_facts['pkg_mgr']]['ip'] }}" ## Extra storage # An AIO may optionally be built using a second storage device. If a @@ -179,9 +179,9 @@ bootstrap_host_format_options: # # Set the data disk mount options. bootstrap_host_data_mount_options: - machinectl: "noatime,nodiratime,compress=lzo,commit=120,{{ (ansible_kernel is version('4.5', '>=')) | ternary('space_cache=v2', 'space_cache') }}" + machinectl: "noatime,nodiratime,compress=lzo,commit=120,{{ (ansible_facts['kernel'] is version('4.5', '>=')) | ternary('space_cache=v2', 'space_cache') }}" zfs: "defaults" - btrfs: "noatime,nodiratime,compress=lzo,commit=120,{{ (ansible_kernel is version('4.5', '>=')) | ternary('space_cache=v2', 'space_cache') }}" + btrfs: "noatime,nodiratime,compress=lzo,commit=120,{{ (ansible_facts['kernel'] is version('4.5', '>=')) | ternary('space_cache=v2', 'space_cache') }}" xfs: "noatime,nodiratime,logbufs=8,logbsize=256k" ext4: "noatime,nobh,barrier=0,data=writeback" dir: "defaults" diff --git a/tests/roles/bootstrap-host/tasks/check-requirements.yml b/tests/roles/bootstrap-host/tasks/check-requirements.yml index 787f3fdf8b..ed414177a7 100644 --- a/tests/roles/bootstrap-host/tasks/check-requirements.yml +++ b/tests/roles/bootstrap-host/tasks/check-requirements.yml @@ -16,12 +16,10 @@ - name: Check for a supported Operating System assert: that: - - (ansible_distribution == 'Debian' and ansible_distribution_release == 'stretch') or - (ansible_distribution == 'Debian' and ansible_distribution_release == 'buster') or - (ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'bionic') or - (ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'focal') or - (ansible_os_family == 'RedHat' and ansible_distribution_major_version == '8') or - (ansible_os_family == 'Suse' and ansible_distribution_major_version in ['42', '15']) + (ansible_facts['distribution'] == 'Debian' and ansible_facts['distribution_release'] == 'buster') or + (ansible_facts['distribution'] == 'Ubuntu' and ansible_facts['distribution_release'] == 'bionic') or + (ansible_facts['distribution'] == 'Ubuntu' and ansible_facts['distribution_release'] == 'focal') or + (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '8') msg: >- The only supported platforms for this release are Debian Stretch, Ubuntu 18.04 LTS (Bionic), Centos 8, openSUSE Leap 42.X and openSUSE Leap 15.X @@ -82,14 +80,15 @@ Can not find disk {{ bootstrap_host_data_disk_device }} when: - bootstrap_host_data_disk_device != None - - ansible_devices.get(bootstrap_host_data_disk_device) == None + - ansible_facts['devices'] is defined + - ansible_facts['devices'].get(bootstrap_host_data_disk_device) == None tags: - check-disk-size - name: Set data disk facts set_fact: - host_data_disk_sectors: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectors'] | int) }}" - host_data_disk_sectorsize: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectorsize'] | int) }}" + host_data_disk_sectors: "{{ (ansible_facts['devices'][bootstrap_host_data_disk_device]['sectors'] | int) }}" + host_data_disk_sectorsize: "{{ (ansible_facts['devices'][bootstrap_host_data_disk_device]['sectorsize'] | int) }}" when: - bootstrap_host_data_disk_device != None tags: diff --git a/tests/roles/bootstrap-host/tasks/install_packages.yml b/tests/roles/bootstrap-host/tasks/install_packages.yml index 1d5b29f31c..9d4a3635c4 100644 --- a/tests/roles/bootstrap-host/tasks/install_packages.yml +++ b/tests/roles/bootstrap-host/tasks/install_packages.yml @@ -24,7 +24,7 @@ package: name: "{{ packages_install }}" state: present - update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" + update_cache: "{{ (ansible_facts['pkg_mgr'] in ['apt', 'zypper']) | ternary('yes', omit) }}" tags: - install-packages diff --git a/tests/roles/bootstrap-host/tasks/main.yml b/tests/roles/bootstrap-host/tasks/main.yml index e5d5a2bf82..6399f546b3 100644 --- a/tests/roles/bootstrap-host/tasks/main.yml +++ b/tests/roles/bootstrap-host/tasks/main.yml @@ -29,11 +29,11 @@ - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: - - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml" - - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml" - - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml" - - "{{ ansible_distribution | lower }}.yml" - - "{{ ansible_os_family | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" + - "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml" + - "{{ ansible_facts['distribution'] | lower }}.yml" + - "{{ ansible_facts['os_family'] | lower }}.yml" tags: - always @@ -76,7 +76,7 @@ static: no when: - bootstrap_host_loopback_swap | bool - - ansible_swaptotal_mb < 1 + - ansible_facts['swaptotal_mb'] < 1 tags: - prepare-loopback diff --git a/tests/roles/bootstrap-host/tasks/prepare_aio_config.yml b/tests/roles/bootstrap-host/tasks/prepare_aio_config.yml index 9248f24827..ebfe5853d8 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_aio_config.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_aio_config.yml @@ -88,7 +88,7 @@ ceph_apt_repos: ceph: state: "present" - repo: "deb http://{{ nodepool_vars.NODEPOOL_MIRROR_HOST }}/ceph-deb-octopus {{ ansible_distribution_release }} main" + repo: "deb http://{{ nodepool_vars.NODEPOOL_MIRROR_HOST }}/ceph-deb-octopus {{ ansible_facts['distribution_release'] }} main" copy: dest: /etc/openstack_deploy/user_openstackci.yml content: "{{ nodepool_overrides | to_nice_yaml }}" @@ -118,13 +118,13 @@ policy: targeted state: permissive when: - - ansible_selinux.status == "enabled" + - ansible_facts['selinux']['status'] == "enabled" - name: Get systemd version command: "rpm -q systemd" changed_when: false register: systemd_version - when: ansible_os_family | lower == 'redhat' + when: ansible_facts['os_family'] | lower == 'redhat' - name: Set the user_variables config_template: diff --git a/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml b/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml index 2ec1b2b726..12c68794fe 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml @@ -47,7 +47,7 @@ - bootstrap_host_data_disk_device_force | bool - item.device is search(bootstrap_host_data_disk_device) with_items: - - "{{ ansible_mounts }}" + - "{{ ansible_facts['mounts'] }}" - name: Partition the whole data disk for our usage command: "{{ item }}" diff --git a/tests/roles/bootstrap-host/tasks/prepare_loopback_zfs.yml b/tests/roles/bootstrap-host/tasks/prepare_loopback_zfs.yml index 6975f113b6..4a8ffc9a49 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_loopback_zfs.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_loopback_zfs.yml @@ -17,7 +17,7 @@ package: name: "{{ packages_install_zfs }}" state: present - update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" + update_cache: "{{ (ansible_facts['pkg_mgr'] in ['apt', 'zypper']) | ternary('yes', omit) }}" tags: - install-packages diff --git a/tests/roles/bootstrap-host/tasks/prepare_networking.yml b/tests/roles/bootstrap-host/tasks/prepare_networking.yml index 5d9072da0b..565ee49398 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_networking.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_networking.yml @@ -20,7 +20,7 @@ failed_when: firewalld_check.rc > 1 args: warn: false - when: ansible_os_family == 'RedHat' + when: ansible_facts['os_family'] == 'RedHat' - name: Disable firewalld become: True @@ -31,7 +31,7 @@ with_items: - firewalld when: - - ansible_os_family == 'RedHat' + - ansible_facts['os_family'] == 'RedHat' - firewalld_check.rc == 0 - name: Run the systemd-networkd role diff --git a/tests/roles/bootstrap-host/tasks/prepare_squid.yml b/tests/roles/bootstrap-host/tasks/prepare_squid.yml index 27a148d8f4..85f0309742 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_squid.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_squid.yml @@ -17,7 +17,7 @@ package: name: squid state: present - update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" + update_cache: "{{ (ansible_facts['pkg_mgr'] in ['apt', 'zypper']) | ternary('yes', omit) }}" notify: Restart squid tags: - install-packages diff --git a/tests/roles/bootstrap-host/templates/user_variables.aio.yml.j2 b/tests/roles/bootstrap-host/templates/user_variables.aio.yml.j2 index 4583788730..51d681cbbe 100644 --- a/tests/roles/bootstrap-host/templates/user_variables.aio.yml.j2 +++ b/tests/roles/bootstrap-host/templates/user_variables.aio.yml.j2 @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -{% if ansible_os_family | lower == 'redhat' %} +{% if ansible_facts['os_family'] | lower == 'redhat' %} deployment_environment_variables: LIBSYSTEMD_VERSION: {{ systemd_version.stdout_lines[0].split('-')[1] }} {% endif %} @@ -285,7 +285,7 @@ tempest_run_concurrency: 0 deployment_environment_variables: http_proxy: http://172.29.236.100:3128/ https_proxy: http://172.29.236.100:3128/ - no_proxy: "localhost,127.0.0.1,172.29.236.100,{{ bootstrap_host_public_address | default(ansible_default_ipv4.address) }}" + no_proxy: "localhost,127.0.0.1,172.29.236.100,{{ bootstrap_host_public_address | default(ansible_facts['default_ipv4']['address']) }}" # Remove eth0 from all container so there is no default route and everything # must go via the http proxy