Skip to content

Instantly share code, notes, and snippets.

@mwik
mwik / update-known-hosts.yml
Created February 19, 2018 21:14
Ansible playbook to get ssh host keys from Azure virtual machines
---
- hosts: localhost
gather_facts: no
vars:
home: "{{ lookup('env','HOME') }}"
tasks:
- name: Fetch SSH public keys
shell: 'az vm run-command invoke --name {{item}} --command-id RunShellScript --scripts "cat /etc/ssh/ssh_host_ecdsa_key.pub" --query output[0].message | grep -o "ecdsa-sha2-nistp256 .*="'
register: host_key
with_items: "{{groups['all']|sort}}"