Fix: configure etc-hosts for overcloud group

Change the etc-hosts role to run on the overcloud group, as using
``ansible_play_hosts_all`` would exclude hosts when running with a
limit.

Also change the gather-facts-delegated role to run on the overcloud
group. The delegated task needs to be included separately as the hostvar
``ansible_host`` cannot be set dynamically based on a loop item in one
task. We loop over the batch indices here so that the tasks are included
in parallel, rather than in series.

Closes-Bug: #2051714

Change-Id: I0465eafa9e4ff37c96064ea8395f0bd461035b40
This commit is contained in:
Matt Crees 2024-01-31 10:36:19 +00:00
parent dc6dc2ecd9
commit 498de81efe
5 changed files with 30 additions and 12 deletions

View File

@ -3,4 +3,4 @@
customize_etc_hosts: true
# List of hosts to add to /etc/hosts.
etc_hosts_hosts: "{{ ansible_play_hosts_all }}"
etc_hosts_hosts: "{{ groups['overcloud'] }}"

View File

@ -1,8 +1,8 @@
---
gather_facts_delegated_limit_hosts: "{{ ansible_play_hosts_all }}"
gather_facts_delegated_batch_index: "{{ gather_facts_delegated_limit_hosts.index(inventory_hostname) }}"
gather_facts_delegated_batch_size: "{{ gather_facts_delegated_limit_hosts | length }}"
gather_facts_delegated_limit_hosts: "{{ groups['overcloud'] }}"
gather_facts_delegated_batch_index: "{{ ansible_play_batch.index(inventory_hostname) }}"
gather_facts_delegated_batch_count: "{{ ansible_play_batch | length }}"
# Use a python list slice to divide the group up.
# Syntax: [<start index>:<end index>:<step size>]
gather_facts_delegated_delegate_hosts: >-
{{ gather_facts_delegated_limit_hosts[gather_facts_delegated_batch_index | int::gather_facts_delegated_batch_size | int] }}
{{ gather_facts_delegated_limit_hosts[gather_facts_delegated_batch_index | int::gather_facts_delegated_batch_count | int] }}

View File

@ -0,0 +1,12 @@
---
- name: Gather facts for delegated host
any_errors_fatal: true
setup:
filter: "{{ kayobe_ansible_setup_filter }}"
gather_subset: "{{ kayobe_ansible_setup_gather_subset }}"
delegate_facts: True
delegate_to: "{{ delegated_host }}"
# NOTE: Without this, the host's ansible_host variable will not be respected
# when using delegate_to.
vars:
ansible_host: "{{ hostvars[delegated_host].ansible_host | default(delegated_host) }}"

View File

@ -1,10 +1,10 @@
---
- name: Gather facts for all hosts (if using --limit)
setup:
filter: "{{ kayobe_ansible_setup_filter }}"
gather_subset: "{{ kayobe_ansible_setup_gather_subset }}"
delegate_facts: True
delegate_to: "{{ item }}"
with_items: "{{ gather_facts_delegated_delegate_hosts }}"
include_tasks: gather-facts-delegated.yml
vars:
delegated_host: "{{ gather_facts_delegated_delegate_hosts[item | int] }}"
# Loop over the index into each host's batch, so tasks are not all included serially.
with_sequence: start=0 end="{{ gather_facts_delegated_delegate_hosts | length | int - 1 }}"
when:
- not hostvars[item].ansible_facts
- item | int < gather_facts_delegated_delegate_hosts | length
- not hostvars[gather_facts_delegated_delegate_hosts[item | int]].ansible_facts

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixes the bug where /etc/hosts was not populated correctly when running
Kayobe using a host limit.
`LP#2051714 <https://launchpad.net/bugs/2051714>`__