kolla-ansible/ansible/gather-facts.yml
Mark Goddard af6e1ca4fd Support Ansible max_fail_percentage
This allows us to continue execution until a certain proportion of hosts
to fail. This can be useful at scale, where failures are common, and
restarting a deployment is time-consuming.

The default max failure percentage is 100, keeping the default
behaviour. A global max failure percentage may be set via
kolla_max_fail_percentage, and individual services may define a max
failure percentage via <service>_max_fail_percentage.

Note that all hosts in the inventory must be reachable for fact
gathering, even those not included in a --limit.

Closes-Bug: #1833737
Change-Id: I808474a75c0f0e8b539dc0421374b06cea44be4f
2023-12-05 11:49:42 +01:00

78 lines
2.8 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
any_errors_fatal: "{{ kolla_ansible_setup_any_errors_fatal | bool }}"
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: Gather facts
setup:
filter: "{{ kolla_ansible_setup_filter }}"
gather_subset: "{{ kolla_ansible_setup_gather_subset }}"
when:
- not ansible_facts
- name: Gather package facts
package_facts:
when:
- "'packages' not in ansible_facts"
- kolla_action is defined
- kolla_action == "precheck"
- name: Group hosts to determine when using --limit
group_by:
key: "all_using_limit_{{ (ansible_play_batch | length) != (groups['all'] | length) }}"
changed_when: false
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
any_errors_fatal: "{{ kolla_ansible_setup_any_errors_fatal | bool }}"
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: "{{ groups['all'][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 }}"
# We gathered facts for all hosts in the batch during the first play.
when:
- not hostvars[item].ansible_facts
- name: Gather package facts
package_facts:
delegate_facts: True
delegate_to: "{{ item }}"
with_items: "{{ delegate_hosts }}"
when:
- "'packages' not in hostvars[item].ansible_facts"
- kolla_action is defined
- "kolla_action == 'precheck'"
tags: always