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:
parent
6a10f097ce
commit
974b5d7dac
@ -1,3 +1,14 @@
|
|||||||
- hosts: all
|
- name: Configure a multi node environment
|
||||||
roles:
|
hosts: all
|
||||||
- multi-node-known-hosts
|
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
|
||||||
|
2
roles/multi-node-hosts-file/README.rst
Normal file
2
roles/multi-node-hosts-file/README.rst
Normal 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.
|
17
roles/multi-node-hosts-file/tasks/main.yaml
Normal file
17
roles/multi-node-hosts-file/tasks/main.yaml
Normal 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 }}"
|
Loading…
Reference in New Issue
Block a user