Avoid unconditional fact gathering

One way to improve the performance of Ansible is through fact caching.
Rather than gather facts in every play, we can configure Ansible to
cache them in a persistent store. An example Ansible configuration for
doing this is as follows:

[defaults]
gathering = smart
fact_caching = jsonfile
fact_caching_connection = ./facts
fact_caching_timeout = 86400

While this mostly just works, there are a few places where we
unconditionally gather facts using the setup module. This change
modifies these to only gather facts when necessary.

We no longer execute the MichaelRigart.interfaces role using become:
true, since it may gather facts and we do not want it to do so as root.
The role uses become where necessary.

Change-Id: I9984a187fc6c0496ada489bb8eef36e44d695aac
Story: 2007492
Task: 39216
This commit is contained in:
Mark Goddard 2020-03-31 14:52:56 +01:00
parent 939e298c56
commit e924c99c52
8 changed files with 24 additions and 2 deletions

View File

@ -47,6 +47,7 @@
gather_subset: min gather_subset: min
delegate_to: localhost delegate_to: localhost
delegate_facts: true delegate_facts: true
when: not hostvars.localhost.module_setup | default(false)
- name: Reserve TCP ports for ironic serial consoles - name: Reserve TCP ports for ironic serial consoles
include_role: include_role:

View File

@ -15,6 +15,7 @@
delegate_to: localhost delegate_to: localhost
delegate_facts: true delegate_facts: true
run_once: true run_once: true
when: not hostvars.localhost.module_setup | default(false)
- name: Ensure IP addresses are allocated - name: Ensure IP addresses are allocated
hosts: seed-hypervisor:seed:overcloud hosts: seed-hypervisor:seed:overcloud

View File

@ -36,6 +36,7 @@
- name: Ensure the Kayobe Ansible user account exists - name: Ensure the Kayobe Ansible user account exists
hosts: kayobe_user_bootstrap_required_True hosts: kayobe_user_bootstrap_required_True
gather_facts: false
tags: tags:
- kayobe-ansible-user - kayobe-ansible-user
vars: vars:

View File

@ -19,6 +19,8 @@
- block: - block:
- name: Gather facts - name: Gather facts
setup: setup:
when: not module_setup | default(false)
register: gather_facts
- name: Ensure the Python virtualenv package is installed - name: Ensure the Python virtualenv package is installed
package: package:
@ -82,6 +84,16 @@
ansible_python_interpreter: /usr/libexec/platform-python ansible_python_interpreter: /usr/libexec/platform-python
when: virtualenv is defined 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:
when:
- virtualenv is defined
- gather_facts is not skipped
- lookup('config', 'DEFAULT_GATHERING') != 'implicit'
- block: - block:
- name: Ensure Python setuptools and pip packages are installed - name: Ensure Python setuptools and pip packages are installed
vars: vars:

View File

@ -21,7 +21,7 @@
- block: - block:
- name: Gather facts - name: Gather facts
setup: setup:
when: ansible_python is not defined when: not module_setup | default(false)
- name: Ensure the Python virtualenv package is installed - name: Ensure the Python virtualenv package is installed
package: package:

View File

@ -67,7 +67,6 @@
{{ bond_interfaces | {{ bond_interfaces |
map('net_bond_obj') | map('net_bond_obj') |
list }} list }}
become: True
# Configure virtual ethernet patch links to connect the workload provision # Configure virtual ethernet patch links to connect the workload provision
# and external network bridges to the Neutron OVS bridge. # and external network bridges to the Neutron OVS bridge.

View File

@ -9,6 +9,7 @@
# Facts required for ansible_user_uid and ansible_user_gid. # Facts required for ansible_user_uid and ansible_user_gid.
- name: Gather facts for swift ring build host - name: Gather facts for swift ring build host
setup: setup:
when: not module_setup | default(false)
- name: Ensure Swift ring build directory exists - name: Ensure Swift ring build directory exists
file: file:

View File

@ -0,0 +1,7 @@
---
upgrade:
- |
Avoids unnecessary fact gathering using the ``setup`` module. This should
improve the performance of environments using fact caching and the Ansible
``smart`` fact gathering policy. See `story 2007492
<https://storyboard.openstack.org/#!/story/2007492>`__ for details.