summaryrefslogtreecommitdiffstats
path: root/ssh.yml
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2018-07-05 16:22:30 +0200
committerSuren A. Chilingaryan <csa@suren.me>2018-07-05 16:22:30 +0200
commit5416f8599ffa92b69bb87434dc1175d760760bbe (patch)
tree307218127ade7099282ac3bef123a2e9590e8f13 /ssh.yml
downloaditm-5416f8599ffa92b69bb87434dc1175d760760bbe.tar.gz
itm-5416f8599ffa92b69bb87434dc1175d760760bbe.tar.bz2
itm-5416f8599ffa92b69bb87434dc1175d760760bbe.tar.xz
itm-5416f8599ffa92b69bb87434dc1175d760760bbe.zip
Initial import
Diffstat (limited to 'ssh.yml')
-rw-r--r--ssh.yml30
1 files changed, 30 insertions, 0 deletions
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 }}"