Here’s a common scenario I’m encountering on Ansible-related forums:
Q: I cannot connect to network devices with my Ansible network modules. I keep getting these weird error messages…
Me: Are you sure you have the device SSH keys in known_hosts file?
Q: How did you know?
Me: Been there, done that…
In my case, the situation got really annoying because I’m using Cisco IOS devices running in VIRL to test my Ansible scripts, and there’s absolutely no way to retain the router SSH keys across device or VIRL reloads.
Finally, I found an Ansible playbook that used ssh-keyscan to collect SSH keys. It was easy to adapt it to collect keys from managed devices and store them in known_hosts file on your Ansible host.