kolla-ansible/ansible/gather-facts.yml
Mark Goddard 94b4adae2f Support reducing scope of delegated fact gathering
When Kolla Ansible is executed with a '--limit' argument, the scope of
an operation is limited to the hosts in the limit. For example:

   kolla-ansible deploy --limit control

Due to the nature of configuring clustered software services, there are
cases where we need to know information about other hosts. Most often
this is related to their hostname or network addresses. To make this
work, Kolla Ansible gathers facts for hosts outside of the limit using
delegated fact gathering [1].

By default, Kolla Ansible gathers facts for all hosts. Because delegated
facts are gathered serially in batches by the active hosts, this can
take a long time when there are not many hosts in the limit.

This change makes it possible to reduce the set of hosts eligible for
delegated fact gathering by setting 'kolla_ansible_delegate_facts_hosts'
to a list of hosts.

[1] https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_delegation.html#delegating-facts

Depends-On: https://review.opendev.org/c/openstack/kolla-ansible/+/899615

Change-Id: Id0bda00b81b5bc6a9a870e231335c33d9828e95f
2025-02-05 23:15:53 +00:00

63 lines
2.4 KiB
YAML

---
# NOTE(awiddersheim): Gather facts for all hosts as a
# first step since several plays below require them when
# building their configurations.
- name: Gather facts for all hosts
hosts: all
max_fail_percentage: >-
{{ gather_facts_max_fail_percentage |
default(kolla_max_fail_percentage) |
default(100) }}
serial: '{{ kolla_serial|default("0") }}'
gather_facts: false
tasks:
- name: Group hosts to determine when using --limit
group_by:
key: "all_using_limit_{{ (ansible_play_batch | length) != (groups['all'] | length) }}"
changed_when: false
- name: Gather facts
setup:
filter: "{{ kolla_ansible_setup_filter }}"
gather_subset: "{{ kolla_ansible_setup_gather_subset }}"
when:
# Don't gather if fact caching is in use
- not ansible_facts
tags: always
# NOTE(pbourke): This case covers deploying subsets of hosts using --limit. The
# limit arg will cause the first play to gather facts only about that node,
# meaning facts such as IP addresses for rabbitmq nodes etc. will be undefined
# in the case of adding a single compute node.
# NOTE(mgoddard): Divide all hosts to be queried between the hosts selected via
# the limit.
- name: Gather facts for all hosts (if using --limit)
hosts: all_using_limit_True
max_fail_percentage: >-
{{ gather_facts_max_fail_percentage |
default(kolla_max_fail_percentage) |
default(100) }}
serial: '{{ kolla_serial|default("0") }}'
gather_facts: false
vars:
batch_index: "{{ ansible_play_batch.index(inventory_hostname) }}"
batch_size: "{{ ansible_play_batch | length }}"
# Use a python list slice to divide the group up.
# Syntax: [<start index>:<end index>:<step size>]
delegate_hosts: "{{ kolla_ansible_delegate_facts_hosts[batch_index | int::batch_size | int] }}"
tasks:
- name: Gather facts
setup:
filter: "{{ kolla_ansible_setup_filter }}"
gather_subset: "{{ kolla_ansible_setup_gather_subset }}"
delegate_facts: True
delegate_to: "{{ item }}"
with_items: "{{ delegate_hosts }}"
when:
# We gathered facts for all hosts in the batch during the first play.
# Ensure that we don't try again if they failed.
- item not in groups["all_using_limit_True"]
# Don't gather if fact caching is in use
- not hostvars[item].ansible_facts
tags: always