From f1e56a32fe62f81f0718701c4cd32f148264e186 Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Mon, 1 Mar 2021 13:21:08 +0000 Subject: [PATCH] Use ansible_facts[] instead of fact variables in playbooks See https://github.com/ansible/ansible/issues/73654 Change-Id: I2c18758c3cb54b171e7b571c21054a69ad67b2ac --- playbooks/ceph-install.yml | 8 +++---- playbooks/ceph-rgw-keystone-setup.yml | 2 +- playbooks/common-tasks/ceph-server.yml | 6 +++--- playbooks/containers-lxc-create.yml | 13 ++---------- playbooks/containers-nspawn-create.yml | 4 ++-- playbooks/defaults/distro_install.yml | 2 +- playbooks/healthcheck-hosts.yml | 12 +++++------ playbooks/healthcheck-infrastructure.yml | 6 +++--- playbooks/infra-journal-remote.yml | 4 ++-- playbooks/openstack-hosts-setup.yml | 21 ++++++++++++------- .../tasks/main.yml | 2 +- playbooks/utility-install.yml | 14 ++++++------- 12 files changed, 46 insertions(+), 48 deletions(-) diff --git a/playbooks/ceph-install.yml b/playbooks/ceph-install.yml index 3c72bc9d87..b3f3196227 100644 --- a/playbooks/ceph-install.yml +++ b/playbooks/ceph-install.yml @@ -37,8 +37,8 @@ owner: "root" mode: "0755" when: - - ansible_pkg_mgr in ['yum', 'dnf'] - - ansible_service_mgr == 'systemd' + - ansible_facts['pkg_mgr'] in ['yum', 'dnf'] + - ansible_facts['service_mgr'] == 'systemd' - name: Add systemd override for PrivateDevices copy: @@ -47,8 +47,8 @@ [Service] PrivateDevices=false when: - - ansible_pkg_mgr in ['yum', 'dnf'] - - ansible_service_mgr == 'systemd' + - ansible_facts['pkg_mgr'] in ['yum', 'dnf'] + - ansible_facts['service_mgr'] == 'systemd' roles: - role: ceph-defaults diff --git a/playbooks/ceph-rgw-keystone-setup.yml b/playbooks/ceph-rgw-keystone-setup.yml index 06b2404e5e..4bab4d4cc3 100644 --- a/playbooks/ceph-rgw-keystone-setup.yml +++ b/playbooks/ceph-rgw-keystone-setup.yml @@ -21,7 +21,7 @@ vars: ansible_python_interpreter: >- {{ openstack_service_setup_host_python_interpreter | - default((openstack_service_setup_host | default('localhost') == 'localhost') | ternary(ansible_playbook_python, ansible_python['executable'])) }} + default((openstack_service_setup_host | default('localhost') == 'localhost') | ternary(ansible_playbook_python, ansible_facts['python']['executable'])) }} tags: - ceph-rgw - ceph-rgw-setup diff --git a/playbooks/common-tasks/ceph-server.yml b/playbooks/common-tasks/ceph-server.yml index f3687d6879..481513c60f 100644 --- a/playbooks/common-tasks/ceph-server.yml +++ b/playbooks/common-tasks/ceph-server.yml @@ -28,7 +28,7 @@ name: libselinux-python3 state: present when: - - ansible_pkg_mgr in ['yum', 'dnf'] + - ansible_facts['pkg_mgr'] in ['yum', 'dnf'] # Set the priority of the ceph community apt repo either above or below that of UCA or distro sources - name: Set apt package pins @@ -39,9 +39,9 @@ apt_package_pinning_priority: "{{ (ceph_repository == 'community') | ternary(1000, 100) }}" apt_pinned_packages: [{ package: '*', release: 'ceph.com' }] when: - - ansible_pkg_mgr == 'apt' + - ansible_facts['pkg_mgr'] == 'apt' - name: Install python3-yaml package: - name: "{{ (ansible_os_family | lower == 'debian') | ternary('python3-yaml', 'python3-pyyaml') }}" + name: "{{ (ansible_facts['os_family'] | lower == 'debian') | ternary('python3-yaml', 'python3-pyyaml') }}" state: present diff --git a/playbooks/containers-lxc-create.yml b/playbooks/containers-lxc-create.yml index ed8b028a35..e59dd75bd8 100644 --- a/playbooks/containers-lxc-create.yml +++ b/playbooks/containers-lxc-create.yml @@ -48,17 +48,8 @@ sleep: "{{ lxc_container_wait_params.sleep | default(omit) }}" timeout: "{{ lxc_container_wait_params.timeout | default(omit) }}" - # When using gather_facts with smart gathering, - # the facts aren't fully updated unless they - # are old. Using the setup module in a task - # does a more thorough collection. - # Given we've just created the container, it is - # best that we do a full collection of facts - - # otherwise we end up with a stale set which - # has stuff like the hostname = localhost. - - name: Gather facts for new container(s) - setup: - gather_subset: "network,hardware,virtual" + - name: Clear facts for new container(s) + meta: clear_facts - name: Gather lxc containers facts hosts: all_lxc_containers diff --git a/playbooks/containers-nspawn-create.yml b/playbooks/containers-nspawn-create.yml index 6eedea120a..d16fa5acc6 100644 --- a/playbooks/containers-nspawn-create.yml +++ b/playbooks/containers-nspawn-create.yml @@ -89,7 +89,7 @@ retries: 5 delay: 15 when: - - ansible_pkg_mgr == 'apt' + - ansible_facts['pkg_mgr'] == 'apt' - name: Update package cache (zypper) zypper_repository: @@ -100,7 +100,7 @@ retries: 5 delay: 15 when: - - ansible_pkg_mgr == 'zypper' + - ansible_facts['pkg_mgr'] == 'zypper' # When using gather_facts with smart gathering, # the facts aren't fully updated unless they diff --git a/playbooks/defaults/distro_install.yml b/playbooks/defaults/distro_install.yml index 9a6c6c6a09..7fc794243d 100644 --- a/playbooks/defaults/distro_install.yml +++ b/playbooks/defaults/distro_install.yml @@ -69,7 +69,7 @@ zun_install_method: distro ## Delegate all database setup tasks to the utility host, and use the utility venv python interpreter openstack_db_setup_host: "{{ groups['utility_all'][0] }}" -openstack_db_setup_python_interpreter: "{{ ansible_python['executable'] }}" +openstack_db_setup_python_interpreter: "{{ ansible_facts['python']['executable'] }}" openstack_service_setup_host: "{{ groups['utility_all'][0] }}" openstack_service_setup_host_python_interpreter: "/usr/bin/python3" diff --git a/playbooks/healthcheck-hosts.yml b/playbooks/healthcheck-hosts.yml index 21fdd23904..d762f1590b 100644 --- a/playbooks/healthcheck-hosts.yml +++ b/playbooks/healthcheck-hosts.yml @@ -46,7 +46,7 @@ - name: Ensure the physical host has all the proper interfaces defined assert: that: - - item.value.bridge in hostvars[physical_host]['ansible_interfaces'] + - item.value.bridge in hostvars[physical_host]['ansible_facts']['interfaces'] with_dict: "{{ container_networks }}" - name: Check if dns resolution and external connectivity is fine @@ -73,7 +73,7 @@ tasks: - name: Open modules file slurp: - src: "{{ (ansible_os_family | lower == 'debian') | ternary('/etc/modules', '/etc/modules-load.d/openstack-ansible.conf') }}" + src: "{{ (ansible_facts['os_family'] | lower == 'debian') | ternary('/etc/modules', '/etc/modules-load.d/openstack-ansible.conf') }}" register: modules_file - name: Open sysctl file @@ -105,12 +105,12 @@ - name: Check for systat file stat: - path: "{{ (ansible_os_family | lower == 'debian') | ternary('/etc/default/sysstat', '/etc/sysconfig/sysstat') }}" + path: "{{ (ansible_facts['os_family'] | lower == 'debian') | ternary('/etc/default/sysstat', '/etc/sysconfig/sysstat') }}" register: systat_file - name: Check for ssh dir stat: - path: "{{ ansible_env.HOME }}/.ssh" + path: "{{ ansible_facts['env']['HOME'] }}/.ssh" register: ssh_dir - name: Check role functions @@ -119,8 +119,8 @@ - "'dm_multipath' in modules_content" - "'ebtables' in modules_content" - "'vm.swappiness' in sysctl_content" - - "'172.29.236.100 {{ ansible_fqdn }} {{ ansible_hostname }}' in hosts_content" - - "'{{ hostvars[groups['galera_all'][0]]['container_address'] }} {{ hostvars[groups['galera_all'][0]]['ansible_hostname'] }}.openstack.local {{ hostvars[groups['galera_all'][0]]['ansible_hostname'] ~ ((hostvars[groups['galera_all'][0]]['ansible_hostname'] != groups['galera_all'][0]) | ternary(' ' ~ groups['galera_all'][0], '')) }}' in hosts_content" + - "'172.29.236.100 {{ ansible_facts['fqdn'] }} {{ ansible_facts['hostname'] }}' in hosts_content" + - "'{{ hostvars[groups['galera_all'][0]]['container_address'] }} {{ hostvars[groups['galera_all'][0]]['ansible_facts']['hostname'] }}.openstack.local {{ hostvars[groups['galera_all'][0]]['ansible_facts']['hostname'] ~ ((hostvars[groups['galera_all'][0]]['ansible_facts']['hostname'] != groups['galera_all'][0]) | ternary(' ' ~ groups['galera_all'][0], '')) }}' in hosts_content" - "release_file.stat.exists" - "systat_file.stat.exists" - "'PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' in environment_content" diff --git a/playbooks/healthcheck-infrastructure.yml b/playbooks/healthcheck-infrastructure.yml index cc9e2dafc4..4f46575fd2 100644 --- a/playbooks/healthcheck-infrastructure.yml +++ b/playbooks/healthcheck-infrastructure.yml @@ -50,7 +50,7 @@ when: groups['haproxy'] | length > 1 - package: - name: "{% if ansible_os_family | lower == 'redhat' %}nmap-ncat{% else %}netcat-openbsd{% endif %}" + name: "{% if ansible_facts['os_family'] | lower == 'redhat' %}nmap-ncat{% else %}netcat-openbsd{% endif %}" state: present # Fails if HAProxy is not running @@ -97,7 +97,7 @@ vars_files: - "defaults/{{ install_method }}_install.yml" vars: - ansible_python_interpreter: "{{ openstack_service_setup_host_python_interpreter | default(ansible_python['executable']) }}" + ansible_python_interpreter: "{{ openstack_service_setup_host_python_interpreter | default(ansible_facts['python']['executable']) }}" tasks: - name: Get openstack client config openstack.cloud.os_client_config: @@ -121,7 +121,7 @@ with_items: "{{ groups['memcached'] }}" - package: - name: "{% if ansible_os_family | lower == 'redhat' %}nmap-ncat{% else %}netcat-openbsd{% endif %}" + name: "{% if ansible_facts['os_family'] | lower == 'redhat' %}nmap-ncat{% else %}netcat-openbsd{% endif %}" state: present - name: Connect to remote memcache servers (full mesh testing) diff --git a/playbooks/infra-journal-remote.yml b/playbooks/infra-journal-remote.yml index e3681ec9ae..5be946df31 100644 --- a/playbooks/infra-journal-remote.yml +++ b/playbooks/infra-journal-remote.yml @@ -35,7 +35,7 @@ - name: Omit suse from this playbook meta: end_play when: - - ansible_pkg_mgr == 'zypper' + - ansible_facts['pkg_mgr'] == 'zypper' - name: Skip playbook if log_hosts group is empty meta: end_play @@ -44,7 +44,7 @@ - name: Install systemd-journal-remote package: - name: "{{ systemd_journal_remote_distro_package[ansible_pkg_mgr] }}" + name: "{{ systemd_journal_remote_distro_package[ansible_facts['pkg_mgr']] }}" state: "{{ package_state }}" - name: Ensure systemd-journal-remote socket is enabled on receiving host diff --git a/playbooks/openstack-hosts-setup.yml b/playbooks/openstack-hosts-setup.yml index 34e0fb4aea..3b6b307b9d 100644 --- a/playbooks/openstack-hosts-setup.yml +++ b/playbooks/openstack-hosts-setup.yml @@ -17,7 +17,7 @@ # that Ubuntu nodes may not have python by default. Ansible doesn't work very # well if Python isn't installed. # -# Also, we can't use a 'when' to check for the ansible_pkg_mgr here because +# Also, we can't use a 'when' to check for the ansible_facts['pkg_mgr'] here because # we haven't gathered facts yet. - name: Install Ansible prerequisites hosts: "{{ openstack_host_group|default('hosts') }}" @@ -41,7 +41,14 @@ - name: Gather host facts hosts: "{{ openstack_host_group|default('hosts') }}" - gather_facts: "{{ osa_gather_facts | default(True) }}" + tasks: + - setup: + gather_subset: + - '!all' + - min + - virtual + when: + - osa_gather_facts | default(True) tags: - always @@ -53,17 +60,17 @@ - name: Check for a supported Operating System assert: that: - - (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') + - (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 10 (Buster), Ubuntu 18.04 LTS (Bionic), Ubuntu 20.04 LTS (Focal) and CentOS 8 - name: Check for a supported path assert: that: - - not (ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'bionic' and install_method == 'distro') + - not (ansible_facts['distribution'] == 'Ubuntu' and ansible_facts['distribution_release'] == 'bionic' and install_method == 'distro') msg: Distro installation path is not supported for this release for Ubuntu 18.04 (bionic) roles: - role: "openstack_hosts" diff --git a/playbooks/roles/system_crontab_coordination/tasks/main.yml b/playbooks/roles/system_crontab_coordination/tasks/main.yml index 9ddf7fc584..9b7245ab22 100644 --- a/playbooks/roles/system_crontab_coordination/tasks/main.yml +++ b/playbooks/roles/system_crontab_coordination/tasks/main.yml @@ -21,4 +21,4 @@ group: "root" mode: "0644" when: - - ansible_os_family == 'Debian' + - ansible_facts['os_family'] == 'Debian' diff --git a/playbooks/utility-install.yml b/playbooks/utility-install.yml index ddc0a3f21e..d6dc700279 100644 --- a/playbooks/utility-install.yml +++ b/playbooks/utility-install.yml @@ -80,7 +80,7 @@ block: - name: Download EPEL gpg keys get_url: - url: "{{ centos_epel_key | default('http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-' ~ ansible_distribution_major_version) }}" + url: "{{ centos_epel_key | default('http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-' ~ ansible_facts['distribution_major_version']) }}" dest: /etc/pki/rpm-gpg register: _get_yum_keys until: _get_yum_keys is success @@ -89,15 +89,15 @@ - name: Install EPEL gpg keys rpm_key: - key: "/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}" + key: "/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{{ ansible_facts['ansible_distribution_major_version'] }}" state: present - name: Install the EPEL repository yum_repository: name: epel-utility baseurl: "{{ centos_epel_mirror | default('http://download.fedoraproject.org/pub/epel') ~ '/' - ~ ansible_distribution_major_version ~ '/' - ~ ansible_architecture }}" + ~ ansible_facts['distribution_major_version'] ~ '/' + ~ ansible_facts['architecture'] }}" description: 'Extra Packages for Enterprise Linux 7 - $basearch' gpgcheck: yes enabled: yes @@ -109,15 +109,15 @@ delay: 2 when: - install_method == "distro" - - ansible_os_family | lower == 'redhat' + - ansible_facts['os_family'] | lower == 'redhat' - ansible_distribution_major_version is version('8', '<') - name: Install distro packages package: name: "{{ utility_distro_packages | default([]) }}" state: "{{ utility_package_state }}" - update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" - cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" + update_cache: "{{ (ansible_facts['pkg_mgr'] in ['apt', 'zypper']) | ternary('yes', omit) }}" + cache_valid_time: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary(cache_timeout, omit) }}" register: install_packages until: install_packages is success retries: 5