Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add host to known_hosts file without prompt

Tags:

ansible

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?

like image 488
Ryan-Neal Mes Avatar asked Jan 11 '16 09:01

Ryan-Neal Mes


People also ask

How do I add a host to ssh?

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.

How do you become known host?

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.

What is known_hosts in .ssh folder?

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.


1 Answers

@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.

like image 132
Bernardo Vale Avatar answered Nov 15 '22 12:11

Bernardo Vale