zuul-jobs/roles/multi-node-hosts-file/tasks/main.yaml
Albin Vass 9062289151 Check for loop_control in with_ type loops
Change-Id: I191265df7709a6262b44a428d78fe28ffaeb4b75
2020-05-01 13:45:34 +02:00

21 lines
657 B
YAML

- 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']}) -%}
{% set _ = hosts.update({vars['ansible_hostname']: 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: "{{ zj_host_address.value }} {{ zj_host_address.key }}"
with_dict: "{{ host_addresses }}"
loop_control:
loop_var: zj_host_address