![Mark Goddard](/assets/img/avatar_default.png)
Ansible facts can have a large impact on the performance of the Ansible control host. This patch introduces some control over which facts are gathered (kayobe_ansible_setup_gather_subset) and which facts are stored (kayobe_ansible_setup_filter). By default we do not change the default values of these arguments to the setup module. The flexibility of these arguments is limited, but they do provide enough for a large performance improvement in a typical moderate to large OpenStack cloud. In particular, the large complex dict fact for each interface has a large effect, and on an OpenStack controller or hypervisor there may be many virtual interfaces. We can use the kayobe_ansible_setup_filter variable to help: kayobe_ansible_setup_filter: 'ansible_[!qt]*' This causes Ansible to collect but not store facts matching that pattern, which includes the virtual interface facts. Currently we are not referencing other facts matching the pattern within Kayobe. Note that including the 'ansible_' prefix causes meta facts module_setup and gather_subset to be filtered, but this seems to be the only way to get a good match on the interface facts. To work around this, we use ansible_facts rather than module_setup to detect whether facts exist in the cache. The exact improvement will vary, but has been reported to be as large as 18x on systems with many virtual interfaces. This change also introduces a new command to gather facts for Kayobe & Kolla Ansible on demand, 'kayobe overcloud facts gather'. This can be used to populate a fact cache. Depends-On: https://review.opendev.org/c/openstack/kolla-ansible/+/794610 Story: 2007993 Task: 42586 Change-Id: I5ce3c734433e1682ee942867505468c57440e689
102 lines
3.6 KiB
YAML
102 lines
3.6 KiB
YAML
---
|
|
# Create a virtualenv for ansible modules to use on the remote target systems
|
|
# when running kayobe.
|
|
|
|
- name: Ensure a virtualenv exists for kayobe
|
|
hosts: seed:seed-hypervisor:overcloud
|
|
gather_facts: False
|
|
tags:
|
|
- kayobe-target-venv
|
|
tasks:
|
|
- name: Set a fact about the kayobe target virtualenv
|
|
set_fact:
|
|
virtualenv: "{{ ansible_python_interpreter | dirname | dirname }}"
|
|
when:
|
|
- ansible_python_interpreter is defined
|
|
- not ansible_python_interpreter.startswith('/bin')
|
|
- not ansible_python_interpreter.startswith('/usr/bin')
|
|
|
|
- block:
|
|
- name: Gather facts
|
|
setup:
|
|
filter: "{{ kayobe_ansible_setup_filter }}"
|
|
gather_subset: "{{ kayobe_ansible_setup_gather_subset }}"
|
|
when: not ansible_facts
|
|
register: gather_facts
|
|
|
|
- name: Ensure the Python virtualenv package is installed
|
|
package:
|
|
name: python3-virtualenv
|
|
state: present
|
|
cache_valid_time: "{{ apt_cache_valid_time if ansible_facts.os_family == 'Debian' else omit }}"
|
|
update_cache: "{{ True if ansible_facts.os_family == 'Debian' else omit }}"
|
|
become: True
|
|
|
|
- name: Ensure global virtualenv directory exists
|
|
file:
|
|
path: "{{ virtualenv_path }}"
|
|
state: directory
|
|
owner: "{{ ansible_facts.user_uid }}"
|
|
group: "{{ ansible_facts.user_gid }}"
|
|
mode: 0755
|
|
# Check whether the virtualenv directory is a subdirectory of the
|
|
# global virtualenv directory.
|
|
when: virtualenv.startswith(virtualenv_path)
|
|
become: True
|
|
|
|
- name: Ensure kayobe virtualenv directory exists
|
|
file:
|
|
path: "{{ virtualenv }}"
|
|
state: directory
|
|
owner: "{{ ansible_facts.user_uid }}"
|
|
group: "{{ ansible_facts.user_gid }}"
|
|
mode: 0700
|
|
become: True
|
|
|
|
- name: Ensure kayobe virtualenv has the latest version of pip installed
|
|
pip:
|
|
name: pip
|
|
state: latest
|
|
virtualenv: "{{ virtualenv }}"
|
|
# Site packages are required for using the dnf module, which is not
|
|
# available via PyPI.
|
|
virtualenv_site_packages: True
|
|
virtualenv_python: "python3.{{ ansible_facts.python.version.minor }}"
|
|
|
|
- name: Ensure kayobe virtualenv has SELinux bindings installed
|
|
pip:
|
|
name: selinux
|
|
state: latest
|
|
virtualenv: "{{ virtualenv }}"
|
|
when:
|
|
- ansible_facts.os_family == 'RedHat'
|
|
vars:
|
|
# Use the system python interpreter since the virtualenv might not
|
|
# exist.
|
|
ansible_python_interpreter: /usr/bin/python3
|
|
when: virtualenv is defined
|
|
|
|
# If we gathered facts earlier it would have been with a different Python
|
|
# interpreter. For gathering modes that may use a fact cache, gather facts
|
|
# again using the interpreter from the virtual environment.
|
|
- name: Gather facts
|
|
setup:
|
|
filter: "{{ kayobe_ansible_setup_filter }}"
|
|
gather_subset: "{{ kayobe_ansible_setup_gather_subset }}"
|
|
when:
|
|
- virtualenv is defined
|
|
- gather_facts is not skipped
|
|
- lookup('config', 'DEFAULT_GATHERING') != 'implicit'
|
|
|
|
- block:
|
|
- name: Ensure Python setuptools and pip packages are installed
|
|
vars:
|
|
packages:
|
|
- python3-setuptools
|
|
- python3-pip
|
|
package:
|
|
name: "{{ packages | select | list }}"
|
|
state: present
|
|
become: True
|
|
when: virtualenv is not defined
|