Ansible – SSH Known Host Keys

I wanted to throw this together mainly for my own reference but maybe it will help someone else as well. I had a need to add every host’s ssh keys to every host so that every host knew what every other hosts ssh keys were. After a bit of attempting many different things below is what I came up with. And it works.

First create a simple playbook:

Next create this simple template:

Then run

ansible-playbook -i yourinventoryfile ssh-keys.yml

and it will run through each host and capture their respective ssh key and then create /etc/ssh/ssh_known_hosts on each host including all other hosts ssh keys as well. Pretty simple after quite a bit of trial and error but it does work.


About Larry Smith Jr.

vExpert 2013-2016 | Old-School coder coming back around to my roots #DevOPS and #automation | #Ansible junky!

Leave a Reply

Your email address will not be published. Required fields are marked *