diff --git a/tasks/file.yml b/tasks/file.yml index 2b02c9e..12095e0 100644 --- a/tasks/file.yml +++ b/tasks/file.yml @@ -1,10 +1,10 @@ --- - + - name: write ssh_known_hosts file local_action: known_hosts args: path: "{{ playbook_dir }}/ssh_known_hosts" name: "{{ item }}" - key: "{{ item }},{{ hostvars[item].ssh_ip }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }}" + key: "{{ lookup('template','ssh_host_key.j2') }}" with_items: "{{play_hosts}}" run_once: true diff --git a/templates/ssh_host_key.j2 b/templates/ssh_host_key.j2 index d29c82d..fbb2cc1 100644 --- a/templates/ssh_host_key.j2 +++ b/templates/ssh_host_key.j2 @@ -1 +1,5 @@ -{{ _ssh_key_type[ssh_host_key_type] }} {% if ssh_host_key_type == "ed25519" %}{{ ssh_host_key_ed25519_public }}{% endif %} \ No newline at end of file +{% if hostvars[item].ssh_ip is defined %} +{{ item }},{{ hostvars[item].ssh_ip }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }} +{% else %} +{{ item }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }} +{% endif %}