From a3f973111c3661db87bdf1412c512edf90d378f7 Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Sun, 22 Oct 2017 23:25:51 +0000 Subject: [PATCH] known hosts handling via template --- tasks/file.yml | 4 ++-- templates/ssh_host_key.j2 | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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 %}