From 5416f8599ffa92b69bb87434dc1175d760760bbe Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 5 Jul 2018 16:22:30 +0200 Subject: Initial import --- ssh.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ssh.yml (limited to 'ssh.yml') diff --git a/ssh.yml b/ssh.yml new file mode 100644 index 0000000..43d8d2d --- /dev/null +++ b/ssh.yml @@ -0,0 +1,30 @@ +- name: Store known hosts of 'all' the hosts in the inventory file + hosts: all:localhost + connection: local + tasks: + - delegate_to: "localhost" + set_fact: target_hosts="{{ play_hosts | difference(['localhost']) }}" + + +- name: Store known hosts of 'all' the hosts in the inventory file + hosts: localhost + connection: local + + vars: + ssh_known_hosts_command: "ssh-keyscan -T 10" + ssh_known_hosts_file: "{{ lookup('env','HOME') + '/.ssh/known_hosts' }}" + ssh_known_hosts: "{{ target_hosts }}" + + tasks: + - name: For each host, scan for its ssh public key + shell: "ssh-keyscan {{ item }},`dig +short {{ item }}`" + with_items: "{{ ssh_known_hosts }}" + register: ssh_known_host_results + ignore_errors: yes + + - name: "Add/update the public key of {{ item.item }} in the {{ ssh_known_hosts_file }}" + known_hosts: + name: "{{ item.item }}" + key: "{{ item.stdout }}" + path: "{{ ssh_known_hosts_file }}" + with_items: "{{ ssh_known_host_results.results }}" -- cgit v1.2.1