Skip to content
Snippets Groups Projects
known_hosts.j2 971 B
Newer Older
Jupiter Hu's avatar
Jupiter Hu committed
{% set nodelist = [] %}
Jupiter Hu's avatar
Jupiter Hu committed
{% for node in groups['all'] %}
{% for interface in hostvars[node]['ansible_interfaces'] %}
{% if interface != "lo" %}
{% if hostvars[node]['ansible_ssh_host_key_rsa_public'] %}
{% set host = {'name': node, 'ip': hostvars[node]['ansible_'+interface]['ipv4']['address'], 'keytype':'ssh-rsa', 'key': hostvars[node]['ansible_ssh_host_key_rsa_public']} %}
Jupiter Hu's avatar
Jupiter Hu committed
{% if nodelist.append(host) %}
{% endif %}
{% endif %}
Jupiter Hu's avatar
Jupiter Hu committed
{% if 'ansible_ssh_host_key_ecdsa_public' in hostvars[node] and hostvars[node]['ansible_ssh_host_key_ecdsa_public'] %}
{% set host = {'name': node, 'ip': hostvars[node]['ansible_'+interface]['ipv4']['address'], 'keytype':'ecdsa-sha2-nistp256', 'key': hostvars[node]['ansible_ssh_host_key_ecdsa_public']} %}
{% if nodelist.append(host) %}
{% endif %}
{% endif %}
{% endif %}
Jupiter Hu's avatar
Jupiter Hu committed
{% endfor %}
{% endfor %}

{% for host in nodelist %}
{{ host.ip }} {{ host.keytype }} {{ host.key }}
{{ host.name }} {{ host.keytype }} {{ host.key }}
Jupiter Hu's avatar
Jupiter Hu committed
{% endfor %}