@@ -2,7 +2,6 @@ ssh_host_key_types: | |||||
- ed25519 | - ed25519 | ||||
- ecdsa | - ecdsa | ||||
- rsa | - rsa | ||||
ssh_ip: "{{ansible_host}}" | |||||
ssh_host_key_state: configured | ssh_host_key_state: configured | ||||
ssh_scan_host: "{% if ssh_ip is defined %}{{ ssh_ip }}{% else %}{{inventory_hostname}}{% endif %}" | ssh_scan_host: "{% if ssh_ip is defined %}{{ ssh_ip }}{% else %}{{inventory_hostname}}{% endif %}" | ||||
@@ -4,8 +4,7 @@ | |||||
local_action: known_hosts | local_action: known_hosts | ||||
args: | args: | ||||
path: "{{ lookup('env','HOME') }}/.ssh/known_hosts" | path: "{{ lookup('env','HOME') }}/.ssh/known_hosts" | ||||
name: "{{ item }}" | |||||
name: "{{ inventory_hostname }}" | |||||
key: "{{ lookup('template','ssh_host_key.j2') }}" | key: "{{ lookup('template','ssh_host_key.j2') }}" | ||||
with_items: "{{play_hosts}}" | |||||
when: hostvars[item].ssh_host_key_ed25519_public is defined | |||||
run_once: true | |||||
when: ssh_host_key_ed25519_public is defined | |||||
throttle: 1 |
@@ -1,13 +1,14 @@ | |||||
--- | --- | ||||
- name: host_vars directory | |||||
- name: make sure host_vars directory is present for host | |||||
local_action: file | local_action: file | ||||
args: | args: | ||||
path: "{{inventory_dir}}/host_vars/{{inventory_hostname}}" | path: "{{inventory_dir}}/host_vars/{{inventory_hostname}}" | ||||
state: directory | state: directory | ||||
- name: host_vars file | |||||
local_action: template | |||||
- name: record ssh host key in host_vars | |||||
local_action: copy | |||||
args: | args: | ||||
src: host_vars.j2 | |||||
dest: "{{inventory_dir}}/host_vars/{{inventory_hostname}}/ssh_host_key.yaml" | |||||
content: | |||||
ssh_host_key_ed25519_public: "{{ ssh_host_key_ed25519_public }}" | |||||
dest: "{{inventory_dir}}/host_vars/{{inventory_hostname}}/ssh_host_key.auto.json" |
@@ -1 +0,0 @@ | |||||
ssh_host_key_ed25519_public: {{ ssh_host_key_ed25519_public }} |
@@ -1,5 +1,5 @@ | |||||
{% if hostvars[item].ssh_ip is defined %} | |||||
{{ item }},{{ ansible_host }},{{ hostvars[item].ssh_ip }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }} | |||||
{% if ssh_ip is defined %} | |||||
{{ inventory_hostname }},{{ ssh_ip }} ssh-ed25519 {{ ssh_host_key_ed25519_public }} | |||||
{% else %} | {% else %} | ||||
{{ item }},{{ ansible_host }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }} | |||||
{{ inventory_hostname }},{{ ansible_host }} ssh-ed25519 {{ ssh_host_key_ed25519_public }} | |||||
{% endif %} | {% endif %} |