Fix race condition regression

The building of the group "repo_masters" relies on going through
the inventory, but we never check if the hosts are added in a
particular order. While it should follow the ansible inventory
order (that's the play order by default), the inclusion of the
host to a group could happen at any time, because the play runs
all the hosts in parallel.

If we ensure the hosts are run serially, the addition of the
hosts to the architecture dependant repo_ groups will always
be done in the right order.

We can then use these groups to find which host is the first one,
and use it as "repo_master".

Change-Id: I51803dab20e85bd6c100821ce5c1c1ad3226ba29
This commit is contained in:
Jean-Philippe Evrard 2017-06-14 10:53:03 +00:00
parent 79a4f013e1
commit 28b646eb27

View File

@ -15,30 +15,36 @@
- name: Group repo servers by architecture
hosts: repo_all
# Serial 1 avoids race conditions, and makes sures the repo_servers
# are added in the same order as the repo_all inventory
serial: 1
tasks:
- name: Group repo servers by architecture and os version
group_by:
key: repo_servers_{{ ansible_distribution_version }}_{{ ansible_architecture }}
tags:
- always
- repo-build
# Use the 'add_host' module to create the repo_masters group which consists of a
# single host in each distribution/architecture combination. This ensures that
# the repo build happens per architecture and per distribution, covering the needs
# of each of these combinations when deploying.
# Use the 'add_host' module to create the repo_masters group which consists of a
# single host in each distribution/architecture combination. This ensures that
# the repo build happens per architecture and per distribution, covering the needs
# of each of these combinations when deploying.
- name: Prepare group of master repo servers
hosts: localhost
tasks:
- name: Prepare group of master repo servers
local_action:
module: "add_host"
add_host:
name: "{{ item }}"
groups: repo_masters
when:
- "inventory_hostname in groups['repo_servers_' + ansible_distribution_version + '_' + ansible_architecture][0]"
- "item in groups['repo_servers_' + ansible_distribution_version + '_' + ansible_architecture][0]"
with_inventory_hostnames:
- repo_all
tags:
- always
- repo-build
- name: Build new repo packages for a given release
hosts: repo_masters
gather_facts: "{{ gather_facts | default(True) }}"