Use ansible_facts[] instead of fact variables in playbooks

See https://github.com/ansible/ansible/issues/73654

Change-Id: I2c18758c3cb54b171e7b571c21054a69ad67b2ac
This commit is contained in:
Jonathan Rosser 2021-03-01 13:21:08 +00:00
parent 3abb80ec09
commit f1e56a32fe
12 changed files with 46 additions and 48 deletions

View File

@ -37,8 +37,8 @@
owner: "root" owner: "root"
mode: "0755" mode: "0755"
when: when:
- ansible_pkg_mgr in ['yum', 'dnf'] - ansible_facts['pkg_mgr'] in ['yum', 'dnf']
- ansible_service_mgr == 'systemd' - ansible_facts['service_mgr'] == 'systemd'
- name: Add systemd override for PrivateDevices - name: Add systemd override for PrivateDevices
copy: copy:
@ -47,8 +47,8 @@
[Service] [Service]
PrivateDevices=false PrivateDevices=false
when: when:
- ansible_pkg_mgr in ['yum', 'dnf'] - ansible_facts['pkg_mgr'] in ['yum', 'dnf']
- ansible_service_mgr == 'systemd' - ansible_facts['service_mgr'] == 'systemd'
roles: roles:
- role: ceph-defaults - role: ceph-defaults

View File

@ -21,7 +21,7 @@
vars: vars:
ansible_python_interpreter: >- ansible_python_interpreter: >-
{{ openstack_service_setup_host_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: tags:
- ceph-rgw - ceph-rgw
- ceph-rgw-setup - ceph-rgw-setup

View File

@ -28,7 +28,7 @@
name: libselinux-python3 name: libselinux-python3
state: present state: present
when: 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 # Set the priority of the ceph community apt repo either above or below that of UCA or distro sources
- name: Set apt package pins - name: Set apt package pins
@ -39,9 +39,9 @@
apt_package_pinning_priority: "{{ (ceph_repository == 'community') | ternary(1000, 100) }}" apt_package_pinning_priority: "{{ (ceph_repository == 'community') | ternary(1000, 100) }}"
apt_pinned_packages: [{ package: '*', release: 'ceph.com' }] apt_pinned_packages: [{ package: '*', release: 'ceph.com' }]
when: when:
- ansible_pkg_mgr == 'apt' - ansible_facts['pkg_mgr'] == 'apt'
- name: Install python3-yaml - name: Install python3-yaml
package: 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 state: present

View File

@ -48,17 +48,8 @@
sleep: "{{ lxc_container_wait_params.sleep | default(omit) }}" sleep: "{{ lxc_container_wait_params.sleep | default(omit) }}"
timeout: "{{ lxc_container_wait_params.timeout | default(omit) }}" timeout: "{{ lxc_container_wait_params.timeout | default(omit) }}"
# When using gather_facts with smart gathering, - name: Clear facts for new container(s)
# the facts aren't fully updated unless they meta: clear_facts
# 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: Gather lxc containers facts - name: Gather lxc containers facts
hosts: all_lxc_containers hosts: all_lxc_containers

View File

@ -89,7 +89,7 @@
retries: 5 retries: 5
delay: 15 delay: 15
when: when:
- ansible_pkg_mgr == 'apt' - ansible_facts['pkg_mgr'] == 'apt'
- name: Update package cache (zypper) - name: Update package cache (zypper)
zypper_repository: zypper_repository:
@ -100,7 +100,7 @@
retries: 5 retries: 5
delay: 15 delay: 15
when: when:
- ansible_pkg_mgr == 'zypper' - ansible_facts['pkg_mgr'] == 'zypper'
# When using gather_facts with smart gathering, # When using gather_facts with smart gathering,
# the facts aren't fully updated unless they # the facts aren't fully updated unless they

View File

@ -69,7 +69,7 @@ zun_install_method: distro
## Delegate all database setup tasks to the utility host, and use the utility venv python interpreter ## 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_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: "{{ groups['utility_all'][0] }}"
openstack_service_setup_host_python_interpreter: "/usr/bin/python3" openstack_service_setup_host_python_interpreter: "/usr/bin/python3"

View File

@ -46,7 +46,7 @@
- name: Ensure the physical host has all the proper interfaces defined - name: Ensure the physical host has all the proper interfaces defined
assert: assert:
that: that:
- item.value.bridge in hostvars[physical_host]['ansible_interfaces'] - item.value.bridge in hostvars[physical_host]['ansible_facts']['interfaces']
with_dict: "{{ container_networks }}" with_dict: "{{ container_networks }}"
- name: Check if dns resolution and external connectivity is fine - name: Check if dns resolution and external connectivity is fine
@ -73,7 +73,7 @@
tasks: tasks:
- name: Open modules file - name: Open modules file
slurp: 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 register: modules_file
- name: Open sysctl file - name: Open sysctl file
@ -105,12 +105,12 @@
- name: Check for systat file - name: Check for systat file
stat: 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 register: systat_file
- name: Check for ssh dir - name: Check for ssh dir
stat: stat:
path: "{{ ansible_env.HOME }}/.ssh" path: "{{ ansible_facts['env']['HOME'] }}/.ssh"
register: ssh_dir register: ssh_dir
- name: Check role functions - name: Check role functions
@ -119,8 +119,8 @@
- "'dm_multipath' in modules_content" - "'dm_multipath' in modules_content"
- "'ebtables' in modules_content" - "'ebtables' in modules_content"
- "'vm.swappiness' in sysctl_content" - "'vm.swappiness' in sysctl_content"
- "'172.29.236.100 {{ ansible_fqdn }} {{ ansible_hostname }}' 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_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" - "'{{ 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" - "release_file.stat.exists"
- "systat_file.stat.exists" - "systat_file.stat.exists"
- "'PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' in environment_content" - "'PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' in environment_content"

View File

@ -50,7 +50,7 @@
when: groups['haproxy'] | length > 1 when: groups['haproxy'] | length > 1
- package: - 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 state: present
# Fails if HAProxy is not running # Fails if HAProxy is not running
@ -97,7 +97,7 @@
vars_files: vars_files:
- "defaults/{{ install_method }}_install.yml" - "defaults/{{ install_method }}_install.yml"
vars: 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: tasks:
- name: Get openstack client config - name: Get openstack client config
openstack.cloud.os_client_config: openstack.cloud.os_client_config:
@ -121,7 +121,7 @@
with_items: "{{ groups['memcached'] }}" with_items: "{{ groups['memcached'] }}"
- package: - 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 state: present
- name: Connect to remote memcache servers (full mesh testing) - name: Connect to remote memcache servers (full mesh testing)

View File

@ -35,7 +35,7 @@
- name: Omit suse from this playbook - name: Omit suse from this playbook
meta: end_play meta: end_play
when: when:
- ansible_pkg_mgr == 'zypper' - ansible_facts['pkg_mgr'] == 'zypper'
- name: Skip playbook if log_hosts group is empty - name: Skip playbook if log_hosts group is empty
meta: end_play meta: end_play
@ -44,7 +44,7 @@
- name: Install systemd-journal-remote - name: Install systemd-journal-remote
package: package:
name: "{{ systemd_journal_remote_distro_package[ansible_pkg_mgr] }}" name: "{{ systemd_journal_remote_distro_package[ansible_facts['pkg_mgr']] }}"
state: "{{ package_state }}" state: "{{ package_state }}"
- name: Ensure systemd-journal-remote socket is enabled on receiving host - name: Ensure systemd-journal-remote socket is enabled on receiving host

View File

@ -17,7 +17,7 @@
# that Ubuntu nodes may not have python by default. Ansible doesn't work very # that Ubuntu nodes may not have python by default. Ansible doesn't work very
# well if Python isn't installed. # 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. # we haven't gathered facts yet.
- name: Install Ansible prerequisites - name: Install Ansible prerequisites
hosts: "{{ openstack_host_group|default('hosts') }}" hosts: "{{ openstack_host_group|default('hosts') }}"
@ -41,7 +41,14 @@
- name: Gather host facts - name: Gather host facts
hosts: "{{ openstack_host_group|default('hosts') }}" 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: tags:
- always - always
@ -53,17 +60,17 @@
- name: Check for a supported Operating System - name: Check for a supported Operating System
assert: assert:
that: that:
- (ansible_distribution == 'Debian' and ansible_distribution_release == 'buster') or - (ansible_facts['distribution'] == 'Debian' and ansible_facts['distribution_release'] == 'buster') or
(ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'bionic') or (ansible_facts['distribution'] == 'Ubuntu' and ansible_facts['distribution_release'] == 'bionic') or
(ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'focal') or (ansible_facts['distribution'] == 'Ubuntu' and ansible_facts['distribution_release'] == 'focal') or
(ansible_os_family == 'RedHat' and ansible_distribution_major_version == '8') (ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '8')
msg: > msg: >
The only supported platforms for this release are Debian 10 (Buster), The only supported platforms for this release are Debian 10 (Buster),
Ubuntu 18.04 LTS (Bionic), Ubuntu 20.04 LTS (Focal) and CentOS 8 Ubuntu 18.04 LTS (Bionic), Ubuntu 20.04 LTS (Focal) and CentOS 8
- name: Check for a supported path - name: Check for a supported path
assert: assert:
that: 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) msg: Distro installation path is not supported for this release for Ubuntu 18.04 (bionic)
roles: roles:
- role: "openstack_hosts" - role: "openstack_hosts"

View File

@ -21,4 +21,4 @@
group: "root" group: "root"
mode: "0644" mode: "0644"
when: when:
- ansible_os_family == 'Debian' - ansible_facts['os_family'] == 'Debian'

View File

@ -80,7 +80,7 @@
block: block:
- name: Download EPEL gpg keys - name: Download EPEL gpg keys
get_url: 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 dest: /etc/pki/rpm-gpg
register: _get_yum_keys register: _get_yum_keys
until: _get_yum_keys is success until: _get_yum_keys is success
@ -89,15 +89,15 @@
- name: Install EPEL gpg keys - name: Install EPEL gpg keys
rpm_key: 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 state: present
- name: Install the EPEL repository - name: Install the EPEL repository
yum_repository: yum_repository:
name: epel-utility name: epel-utility
baseurl: "{{ centos_epel_mirror | default('http://download.fedoraproject.org/pub/epel') ~ '/' baseurl: "{{ centos_epel_mirror | default('http://download.fedoraproject.org/pub/epel') ~ '/'
~ ansible_distribution_major_version ~ '/' ~ ansible_facts['distribution_major_version'] ~ '/'
~ ansible_architecture }}" ~ ansible_facts['architecture'] }}"
description: 'Extra Packages for Enterprise Linux 7 - $basearch' description: 'Extra Packages for Enterprise Linux 7 - $basearch'
gpgcheck: yes gpgcheck: yes
enabled: yes enabled: yes
@ -109,15 +109,15 @@
delay: 2 delay: 2
when: when:
- install_method == "distro" - install_method == "distro"
- ansible_os_family | lower == 'redhat' - ansible_facts['os_family'] | lower == 'redhat'
- ansible_distribution_major_version is version('8', '<') - ansible_distribution_major_version is version('8', '<')
- name: Install distro packages - name: Install distro packages
package: package:
name: "{{ utility_distro_packages | default([]) }}" name: "{{ utility_distro_packages | default([]) }}"
state: "{{ utility_package_state }}" state: "{{ utility_package_state }}"
update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" update_cache: "{{ (ansible_facts['pkg_mgr'] in ['apt', 'zypper']) | ternary('yes', omit) }}"
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" cache_valid_time: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary(cache_timeout, omit) }}"
register: install_packages register: install_packages
until: install_packages is success until: install_packages is success
retries: 5 retries: 5