Skip to content
Snippets Groups Projects
Commit eacdb420 authored by Chris Hines's avatar Chris Hines
Browse files

Merge branch 'calculateKnownHosts' into 'master'

rework of the known_hosts template for simplicity and robustness

See merge request !47
parents f4f638b8 e799b6ec
No related branches found
No related tags found
No related merge requests found
{% set nodelist = [] %} {% set keytypes = [ { 'type': 'ssh-rsa', 'fact': 'ansible_ssh_host_key_rsa_public' }, { 'type': 'ecdsa-sha2-nistp256', 'fact': 'ansible_ssh_host_key_ecdsa_public'} ] %}
{% for node in groups['all'] %} {% for node in groups['all'] %}
{% for interface in hostvars[node]['ansible_interfaces'] %} {% for hostkey in keytypes %}
{% if interface != "lo" %} {% if hostkey['fact'] in hostvars[node] %}
{% if 'ansible_ssh_host_key_rsa_public' in hostvars[node] %} {{ node }} {{ hostkey['type'] }} {{ hostvars[node][hostkey['fact']] }}
{% set host = {'name': node, 'ip': hostvars[node]['ansible_'+interface]['ipv4']['address'], 'keytype':'ssh-rsa', 'key': hostvars[node]['ansible_ssh_host_key_rsa_public']} %} {% for ip in hostvars[node]['ansible_all_ipv4_addresses'] %}
{% if nodelist.append(host) %} {{ ip }} {{ hostkey['type'] }} {{ hostvars[node][hostkey['fact']] }}
{% endif %} {% endfor %}
{% endif %}
{% if 'ansible_ssh_host_key_ecdsa_public' in hostvars[node] %}
{% 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 %} {% endif %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
{% for host in nodelist %}
{{ host.ip }} {{ host.keytype }} {{ host.key }}
{{ host.name }} {{ host.keytype }} {{ host.key }}
{% endfor %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment