Multi-node: Set up hosts file

This allows nodes in a multi-node job to resolve each other through
their inventory hostname.

Change-Id: I19cc7690d6fea99461bc67a46a09a8037f9c3292
This commit is contained in:
David Moreau-Simard 2017-09-15 22:38:12 -06:00
parent 6a10f097ce
commit 974b5d7dac
No known key found for this signature in database
GPG Key ID: 33A07694CBB71ECC
3 changed files with 33 additions and 3 deletions

View File

@ -1,3 +1,14 @@
- hosts: all
roles:
- multi-node-known-hosts
- name: Configure a multi node environment
hosts: all
tasks:
# TODO: Add groups['all'] | length > 1 conditional when the truncated JSON
# issue is resolved, see:
# - https://github.com/ansible/ansible/issues/30385
# - https://review.openstack.org/#/c/504238/
- name: Set up multi-node known hosts
include_role:
name: multi-node-known-hosts
- name: Set up multi-node hosts file
include_role:
name: multi-node-hosts-file

View File

@ -0,0 +1,2 @@
Configures the inventory hostnames in a multi-node job resolve to their
respective private ipv4 addresses through the /etc/hosts file on each node.

View File

@ -0,0 +1,17 @@
- name: Set up the list of hosts and addresses
set_fact:
host_addresses: >
{% set hosts = {} -%}
{% for host, vars in hostvars.items() -%}
{% set _ = hosts.update({host: vars['nodepool']['private_ipv4']}) -%}
{% endfor -%}
{{- hosts -}}
- name: Add inventory hostnames to the hosts file
become: yes
lineinfile:
dest: /etc/hosts
state: present
insertafter: EOF
line: "{{ item.value }} {{ item.key }}"
with_dict: "{{ host_addresses }}"