Add host to known_hosts file without prompt

I am trying to add a known host to a 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 will receive a hint as above.

I thought this module took care of this? Otherwise, I have to make keyscan weband add it to the known_hosts file.

What am I doing wrong or misunderstanding?

+4
source share
2 answers

The module will take care of this. But there are two problems:

  • Since you are running the task on the target host, Ansible will first try to connect to the host before it can complete your task.

  • In addition, since the task runs on the target host, you will add the fingerprint to the know_hosts file on this computer, rather than locally.

, .

ansible localhost -m known_hosts -a "name=web state=present"

keyscan of web known_hosts.

, , known_hosts , . .

+2

@udondan . :

Ansible. . Ansible , . known_hosts, .

, host_key_checking=False ansible.cfg.

: export ANSIBLE_HOST_KEY_CHECKING=False , . unset ANSIBLE_HOST_KEY_CHECKING

, .

host_key_checking.

+8

Source: https://habr.com/ru/post/1623735/


All Articles