aboutsummaryrefslogtreecommitdiff
path: root/ansible/gather-facts.yml
blob: 4b7de2ee32f61326611015ec74d271095ab86b7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
# 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
      ansible.builtin.group_by:
        key: "all_using_limit_{{ (ansible_play_batch | length) != (groups['all'] | length) }}"
      changed_when: false

    - name: Gather facts
      ansible.builtin.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
      ansible.builtin.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