I am trying to add a known host to the known_hosts file using ansible
vagrant@jedi:/vagrant$ ansible web -m known_hosts -a "name=web state=present"
paramiko: The authenticity of host 'web' can't be established.
The ssh-rsa key fingerprint is afb8cf4885468badb1a7b8afc16ac211.
Are you sure you want to continue connecting (yes/no)?
I keep getting prompted as above.
I thought this module took care of this? Otherwise I should do a keyscan of web
and add that to the known_hosts file.
What am I doing wrong or misunderstanding?
On the Add Host menu, select SSH key within the Authentication type. Click Browse to select the previously mentioned private SSH key, which might require to be uploaded in the local directory in advance. Click Add Host to start the adding host process.
Use the -l option to ssh-keygen to list fingerprints, and the -F option to search for a hostname in your known_hosts file. You can use ssh-keyscan to compare the fingerprint in your known_hosts to the one from the server.
The known_hosts File is a client file containing all remotely connected known hosts, and the ssh client uses this file. This file authenticates for the client to the server they are connecting to. The known_hosts file contains the host public key for all known hosts.
@udondan explained very well. Just another note:
This is the default behaivior of Ansible. It will always check the host key. If Ansible never connected to that host this prompt will appear. That is the reason you aren't able to call known_hosts
module without accepting the key first.
If this is not desirable you can set host_key_checking=False
on ansible.cfg
.
MORE SECURE APPROACH
The best approach is set this variable: export ANSIBLE_HOST_KEY_CHECKING=False
while you're deploying new servers, then remove it. unset ANSIBLE_HOST_KEY_CHECKING
Host key checking it's an important security feature.
Learn more about host_key_checking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With