Use ansible_facts[] instead of fact variables

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

Change-Id: Iec4a2a8c5251ddccedc4310c26c8fd2ca8bdc913
This commit is contained in:
Jonathan Rosser 2021-02-23 09:19:04 +00:00
parent bd63b90aeb
commit 2a533ed185
6 changed files with 24 additions and 23 deletions

View File

@ -27,7 +27,7 @@
# Distribution packages which must be installed # Distribution packages which must be installed
# on all hosts when building python wheels. # on all hosts when building python wheels.
venv_build_base_distro_package_list: "{{ _venv_build_base_distro_package_list[ansible_os_family | lower] }}" venv_build_base_distro_package_list: "{{ _venv_build_base_distro_package_list[ansible_facts['os_family'] | lower] }}"
# Distribution packages which must be installed # Distribution packages which must be installed
# on the host for the purpose of building the # on the host for the purpose of building the
@ -78,7 +78,7 @@ venv_pip_build_args: ""
# the venv. # the venv.
venv_default_pip_install_args: >- venv_default_pip_install_args: >-
{%- if (groups['repo_all'] is defined) and (groups['repo_all'] | length > 0) and (venv_wheel_build_enable | bool) %} {%- if (groups['repo_all'] is defined) and (groups['repo_all'] | length > 0) and (venv_wheel_build_enable | bool) %}
--find-links {{ openstack_repo_url | default('http://localhost') }}/os-releases/{{ openstack_release | default('master') }}/{{ (ansible_distribution | lower) | replace(' ', '_') }}-{{ ansible_distribution_version.split('.')[:2] | join('.') }}-{{ ansible_architecture | lower }} --find-links {{ openstack_repo_url | default('http://localhost') }}/os-releases/{{ openstack_release | default('master') }}/{{ (ansible_facts['distribution'] | lower) | replace(' ', '_') }}-{{ ansible_facts['distribution_version'].split('.')[:2] | join('.') }}-{{ ansible_facts['architecture'] | lower }}
--trusted-host {{ (openstack_repo_url | default('http://localhost')) | urlsplit('hostname') }} --trusted-host {{ (openstack_repo_url | default('http://localhost')) | urlsplit('hostname') }}
{%- endif %} {%- endif %}
@ -118,7 +118,8 @@ venv_wheel_build_enable: "{{ venv_build_host != inventory_hostname }}"
# subsequent venv builds on this host and others. When # subsequent venv builds on this host and others. When
# this is the same as the target host, then we will not # this is the same as the target host, then we will not
# bother building wheels. # bother building wheels.
venv_build_host: "{{ venv_build_targets[ansible_distribution_version][ansible_architecture] }}"
venv_build_host: "{{ venv_build_targets[ansible_facts['distribution_version']][ansible_facts['architecture']] }}"
# The path for the wheel build venv. # The path for the wheel build venv.
# This is the path where a venv will be created on the # This is the path where a venv will be created on the
@ -141,7 +142,7 @@ venv_build_host_requirements_path: >-
# been found that pypiserver hangs when it encounters duplicated # been found that pypiserver hangs when it encounters duplicated
# wheels. # wheels.
venv_build_host_wheel_path: >- venv_build_host_wheel_path: >-
/var/www/repo/os-releases/{{ openstack_release | default('master') }}/{{ (ansible_distribution | lower) | replace(' ', '_') }}-{{ ansible_distribution_version.split('.')[:2] | join('.') }}-{{ ansible_architecture | lower }} /var/www/repo/os-releases/{{ openstack_release | default('master') }}/{{ (ansible_facts['distribution'] | lower) | replace(' ', '_') }}-{{ ansible_facts['distribution_version'].split('.')[:2] | join('.') }}-{{ ansible_facts['architecture'] | lower }}
# The facts to set when the venv changes during a # The facts to set when the venv changes during a
# build, or the installation of a venv. # build, or the installation of a venv.

View File

@ -22,8 +22,8 @@
package: package:
name: "{{ (venv_wheel_build_enable | bool) | ternary(venv_install_distro_package_list, (venv_build_base_distro_package_list | union(venv_build_distro_package_list) | union(venv_install_distro_package_list))) }}" name: "{{ (venv_wheel_build_enable | bool) | ternary(venv_install_distro_package_list, (venv_build_base_distro_package_list | union(venv_build_distro_package_list) | union(venv_install_distro_package_list))) }}"
state: "{{ venv_distro_package_state }}" state: "{{ venv_distro_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(venv_distro_cache_valid_time, omit) }}" cache_valid_time: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary(venv_distro_cache_valid_time, omit) }}"
when: when:
- (venv_build_distro_package_list | length > 0) or - (venv_build_distro_package_list | length > 0) or
(venv_install_distro_package_list | length > 0) (venv_install_distro_package_list | length > 0)
@ -52,7 +52,7 @@
virtualenv virtualenv
--no-download --no-download
--python={{ venv_python_executable }} --python={{ venv_python_executable }}
{{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} {{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('--always-copy', '') }}
{{ venv_install_destination_path }} {{ venv_install_destination_path }}
args: args:
creates: "{{ venv_install_destination_path }}/bin/activate" creates: "{{ venv_install_destination_path }}/bin/activate"

View File

@ -25,7 +25,7 @@
vars: vars:
_venv_python_major_version: "{{ (_python_venv_details.files[0].path | basename)[:-2] }}" _venv_python_major_version: "{{ (_python_venv_details.files[0].path | basename)[:-2] }}"
shell: >- shell: >-
{{ (ansible_pkg_mgr == 'apt') | ternary('dpkg -L ' ~ (venv_packages_to_symlink | join(' ')), 'rpm -ql ' ~ (venv_packages_to_symlink | join(' ')) ) }} {{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('dpkg -L ' ~ (venv_packages_to_symlink | join(' ')), 'rpm -ql ' ~ (venv_packages_to_symlink | join(' ')) ) }}
| egrep '^.*{{ _venv_python_major_version }}.*/(site|dist)-packages/.*' | egrep '^.*{{ _venv_python_major_version }}.*/(site|dist)-packages/.*'
| egrep -v "__pycache__" | egrep -v "__pycache__"
args: args:

View File

@ -28,8 +28,8 @@
package: package:
name: "{{ venv_build_base_distro_package_list | union(venv_build_distro_package_list) }}" name: "{{ venv_build_base_distro_package_list | union(venv_build_distro_package_list) }}"
state: "{{ venv_distro_package_state }}" state: "{{ venv_distro_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(venv_distro_cache_valid_time, omit) }}" cache_valid_time: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary(venv_distro_cache_valid_time, omit) }}"
when: when:
- (venv_build_distro_package_list | length > 0) or - (venv_build_distro_package_list | length > 0) or
(venv_install_distro_package_list | length > 0) (venv_install_distro_package_list | length > 0)
@ -68,7 +68,7 @@
virtualenv virtualenv
--no-download --no-download
--python={{ venv_python_executable }} --python={{ venv_python_executable }}
{{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }} {{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('--always-copy', '') }}
{{ venv_build_host_venv_path }} {{ venv_build_host_venv_path }}
args: args:
creates: "{{ venv_build_host_venv_path }}/bin/activate" creates: "{{ venv_build_host_venv_path }}/bin/activate"

View File

@ -25,9 +25,9 @@
- name: Set venv_build_archive_path and venv_install_source_path - name: Set venv_build_archive_path and venv_install_source_path
set_fact: set_fact:
venv_build_host_wheel_path: >- venv_build_host_wheel_path: >-
{%- if ansible_distribution == "Ubuntu" %} {%- if ansible_facts['distribution'] == "Ubuntu" %}
{%- set _path = "/var/www/html" %} {%- set _path = "/var/www/html" %}
{%- elif ansible_distribution == "CentOS" %} {%- elif ansible_facts['distribution'] == "CentOS" %}
{%- set _path = "/usr/share/nginx/html" %} {%- set _path = "/usr/share/nginx/html" %}
{%- else %} {%- else %}
{%- set _path = "/srv/www/htdocs" %} {%- set _path = "/srv/www/htdocs" %}
@ -39,7 +39,7 @@
key: "http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7" key: "http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7"
state: present state: present
when: when:
- ansible_pkg_mgr in ['yum', 'dnf'] - ansible_facts['pkg_mgr'] in ['yum', 'dnf']
register: _add_yum_keys register: _add_yum_keys
until: _add_yum_keys is success until: _add_yum_keys is success
retries: 5 retries: 5
@ -48,14 +48,14 @@
- name: Install the EPEL repository - name: Install the EPEL repository
yum_repository: yum_repository:
name: epel-nginx name: epel-nginx
baseurl: "{{ (centos_epel_mirror | default ('http://download.fedoraproject.org/pub/epel')) ~ '/' ~ ansible_distribution_major_version ~ ((ansible_distribution_major_version is version('8', '<')) | ternary('/', '/Everything/')) ~ ansible_architecture }}" baseurl: "{{ (centos_epel_mirror | default ('http://download.fedoraproject.org/pub/epel')) ~ '/' ~ ansible_facts['distribution_major_version'] ~ ((ansible_facts['distribution_major_version'] is version('8', '<')) | ternary('/', '/Everything/')) ~ ansible_facts['architecture'] }}"
description: 'Extra Packages for Enterprise Linux - $basearch' description: 'Extra Packages for Enterprise Linux - $basearch'
gpgcheck: yes gpgcheck: yes
enabled: yes enabled: yes
state: present state: present
includepkgs: 'nginx*' includepkgs: 'nginx*'
when: when:
- ansible_pkg_mgr in ['yum', 'dnf'] - ansible_facts['pkg_mgr'] in ['yum', 'dnf']
register: install_epel_repo register: install_epel_repo
until: install_epel_repo is success until: install_epel_repo is success
retries: 5 retries: 5
@ -64,7 +64,7 @@
- name: Install distro packages - name: Install distro packages
package: package:
name: "nginx" name: "nginx"
update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}" update_cache: "{{ (ansible_facts['pkg_mgr'] in ['apt', 'zypper']) | ternary('yes', omit) }}"
register: install register: install
until: install is success until: install is success
retries: 5 retries: 5
@ -143,8 +143,8 @@
- "Jinja2==2.10" - "Jinja2==2.10"
venv_install_destination_path: "/openstack/venvs/test-venv" venv_install_destination_path: "/openstack/venvs/test-venv"
venv_pip_install_args: >- venv_pip_install_args: >-
--find-links http://{{ hostvars['localhost'].ansible_default_ipv4.address }} --find-links http://{{ hostvars['localhost']['ansible_facts']['default_ipv4'].address }}
--trusted-host {{ hostvars['localhost'].ansible_default_ipv4.address }} --trusted-host {{ hostvars['localhost']['ansible_facts']['default_ipv4'].address }}
venv_build_host: localhost venv_build_host: localhost
venv_build_host_wheel_path: "{{ hostvars['localhost']['venv_build_host_wheel_path'] }}" venv_build_host_wheel_path: "{{ hostvars['localhost']['venv_build_host_wheel_path'] }}"
tasks: tasks:

View File

@ -64,14 +64,14 @@ _venv_build_base_distro_package_list:
# for the repo servers. # for the repo servers.
venv_build_targets: |- venv_build_targets: |-
{% set targets = { {% set targets = {
(ansible_distribution_version | string): { (ansible_facts['distribution_version'] | string): {
(ansible_architecture | string): (inventory_hostname | string) (ansible_facts['architecture'] | string): (inventory_hostname | string)
} }
} }
%} %}
{% for item in ((groups['repo_all'] | default([inventory_hostname])) | reverse) %} {% for item in ((groups['repo_all'] | default([inventory_hostname])) | reverse) %}
{% set distro = hostvars[item]['ansible_distribution_version'] %} {% set distro = hostvars[item]['ansible_facts']['distribution_version'] %}
{% set arch = hostvars[item]['ansible_architecture'] %} {% set arch = hostvars[item]['ansible_facts']['architecture'] %}
{% set target_item = {(arch | string): (item | string)} %} {% set target_item = {(arch | string): (item | string)} %}
{% set _ = targets.__setitem__(distro, target_item) %} {% set _ = targets.__setitem__(distro, target_item) %}
{% endfor %} {% endfor %}