f88eb51b71
Ansible-core 2.16.4 appears to have a behavior change where it will include the implicit localhost in hostvars, which means that any location we iterate over hostvars and assume it's a real host could throw an exception. To avoid that, add checks that the variables we are about to access on the host exist. Change-Id: Iff89da761e5f6748b454610a64c2fdd4f5e56a77
28 lines
806 B
YAML
28 lines
806 B
YAML
- name: Test the multi-node-hosts-file role
|
|
hosts: all
|
|
roles:
|
|
- multi-node-hosts-file
|
|
post_tasks:
|
|
- name: lookup hosts file
|
|
command: cat /etc/hosts
|
|
register: hosts_file
|
|
|
|
- name: Set up the list of hosts and addresses
|
|
set_fact:
|
|
host_addresses: >
|
|
{% set hosts = [] -%}
|
|
{% for host, vars in hostvars.items() -%}
|
|
{% if 'nodepool' in vars -%}
|
|
{% set _ = hosts.append({'host': host, 'address': vars['nodepool']['private_ipv4']}) -%}
|
|
{% endif -%}
|
|
{% endfor -%}
|
|
{{- hosts -}}
|
|
|
|
- name: assert that hosts are in the hosts file
|
|
vars:
|
|
line: "{{ item.address }} {{ item.host }}"
|
|
assert:
|
|
that:
|
|
- "line in hosts_file.stdout"
|
|
with_list: "{{ host_addresses }}"
|