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
34 lines
1.1 KiB
YAML
34 lines
1.1 KiB
YAML
- name: Test the multi-node-known-hosts role
|
|
hosts: all
|
|
roles:
|
|
- multi-node-known-hosts
|
|
post_tasks:
|
|
- name: lookup known_hosts file
|
|
command: cat /etc/ssh/ssh_known_hosts
|
|
register: known_hosts
|
|
|
|
- name: Set up host addresses
|
|
set_fact:
|
|
host_addresses: >
|
|
{% set hosts = [] -%}
|
|
{% for host, vars in hostvars.items() -%}
|
|
{% if 'nodepool' in vars -%}
|
|
{% if vars['nodepool']['private_ipv4'] | length > 0 -%}
|
|
{% set _ = hosts.append(vars['nodepool']['private_ipv4']) -%}
|
|
{% endif -%}
|
|
{% if vars['nodepool']['public_ipv4'] | length > 0 -%}
|
|
{% set _ = hosts.append(vars['nodepool']['public_ipv4']) -%}
|
|
{% endif -%}
|
|
{% if vars['nodepool']['public_ipv6'] | length > 0 -%}
|
|
{% set _ = hosts.append(vars['nodepool']['public_ipv6']) -%}
|
|
{% endif -%}
|
|
{% endif -%}
|
|
{% endfor -%}
|
|
{{- hosts | sort | unique -}}
|
|
|
|
- name: assert that hosts are in known_hosts
|
|
assert:
|
|
that:
|
|
- "item in known_hosts.stdout"
|
|
with_items: "{{ host_addresses }}"
|