If you’ve ever tried to run an ansible playbook and recieved Please add this host's fingerprint to your known_hosts file to manage this host
you’re not alone. Here’s a couple of ways to fix it.
Turn off host key checking
This would not be the preferred method but turning off host key checking will enable ansible to continue on with the playbook.
Either modify the /etc/ansible/ansible.cfg
or create an ansible.cfg
file in the project directory and add the following lines to it:
[defaults]
host_key_checking = false
Adding the SSH fingerprint to the known_hosts file
This is the preferred method to fix the issue. If the host key changes in the future you’ll be alerted that something has happened to the remote server and be able to investigate.
ssh-keyscan -H example.com >> ~/.ssh/known_hosts
If your inventory file is in the ini format this command can add all hosts to the known_hosts file in one line:
ssh-keyscan -H $(cut -d ' ' -f 1 inventory) >> ~/.ssh/known_hosts
Bonus Environment Variable
It’s also possible to set an environment variable to allow skipping the host fingerprint check.
export ANSIBLE_HOST_KEY_CHECKING=False