<p>You can add this in inventory:</p>

<pre><code>ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
</code></pre>

<p>It's ignoring check host and setting /dev/null as Known host file.</p>

CC BY-SA 4.0
2020-05-06T05:56:26.150Z
Please explain what this will do and remove the spaces at the beginning of the code block
030
CC BY-SA 4.0
2020-05-06T03:09:52.167Z
2020-05-06T06:25:27.347Z
2020-05-06T06:25:27.347Z
Dilson Rainov
<p>I've followed the recommendations I could find to prevent this from happening.  I am using Vagrant, but once the boxes are spun, I'd like to do things with the <code>ansible</code> command sometimes.</p>

<pre><code>$ grep host_key /etc/ansible/ansible.cfg                                                                                                               
host_key_checking = False

$ grep kafka01 ./inventory
kafka01 ansible_host=127.0.0.1 ansible_port=2231 ansible_user='vagrant' ansible_ssh_private_key_file='/home/me/project/project/.vagrant/machines/kafka01/virtualbox/private_key' ansible_ssh_common_args='-o StrictHostKeyChecking=no'

$ export ANSIBLE_HOST_KEY_CHECKING=False
$ ansible kafka01 -m ping -i ./inventory                                                                                                               

 [WARNING]: Unhandled error in Python interpreter discovery for host kafka01: Failed to connect to the host via ssh: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @    WARNING:
REMOTE HOST IDENTIFICATION HAS CHANGED!     @  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!  Someone could be eavesdropping on
you right now (man-in-the-middle attack)!  It is also possible that a host key has just been changed.  The fingerprint for the ECDSA key sent by the remote host is
SHA256:jn5ClU5g566Gsvobf8Xc45DJnIiAllN+RJkg35Nf9KE.  Please contact your system administrator.  Add correct host key in /home/me/.ssh/known_hosts to get rid of this message.  Offending ECDSA key
in /home/me/.ssh/known_hosts:19    remove with:    ssh-keygen -f "/home/me/.ssh/known_hosts" -R "[127.0.0.1]:2231"  ECDSA host key for [127.0.0.1]:2231 has changed and you have requested strict
checking.  Host key verification failed.

kafka01 | UNREACHABLE! =&gt; {
.....
</code></pre>

<p>What's going on here?</p>

<p>Edit: No, I don't want to keep deleting the key.  I destroy/build these over and over again.  I want to find the correct, long-term solution.</p>

CC BY-SA 4.0
2020-04-09T04:43:25.490Z
`It is also possible that a host key has just been changed.` try to remove the client entry in `/home/me/.ssh/known_hosts`
Siva
CC BY-SA 4.0
2020-04-09T08:22:53.230Z
... by the command proposed in the message `ssh-keygen -f "/home/me/.ssh/known_hosts" -R "[127.0.0.1]:2231`
Vladimir Botka
CC BY-SA 4.0
2020-04-09T15:10:13.047Z
@msp9011 That's the obvious answer, right?  Problem is after I destroy then rebuild the keys have changed again.  I don't want to keep deleting them.
Ken - Enough about Monica
CC BY-SA 4.0
2020-04-10T20:33:26.553Z
@msp9011 only /etc/ansible/
Ken - Enough about Monica
CC BY-SA 4.0
2020-04-11T03:50:25.813Z
can u plz share version of ansible
Siva
CC BY-SA 4.0
2020-04-11T03:54:07.163Z
try adding `UserKnownHostsFile=/dev/null` in sshCommonArgs as `ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
Siva
<ansible><vagrant>
Ansible warning that host key has changed, even though I've taken multiple steps to prevent this warning
Ken - Enough about Monica
# Ansible warning that host key has changed, even though I've taken multiple steps to prevent this warning

(Asked by: username_0 on 2020-04-09)

I've followed the recommendations I could find to prevent this from happening.  I am using Vagrant, but once the boxes are spun, I'd like to do things with the ansible command sometimes.
$ grep host_key /etc/ansible/ansible.cfg                                                                                                               
host_key_checking = False

$ grep kafka01 ./inventory
kafka01 ansible_host=127.0.0.1 ansible_port=2231 ansible_user='vagrant' ansible_ssh_private_key_file='/home/me/project/project/.vagrant/machines/kafka01/virtualbox/private_key' ansible_ssh_common_args='-o StrictHostKeyChecking=no'

$ export ANSIBLE_HOST_KEY_CHECKING=False
$ ansible kafka01 -m ping -i ./inventory                                                                                                               

 [WARNING]: Unhandled error in Python interpreter discovery for host kafka01: Failed to connect to the host via ssh: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @    WARNING:
REMOTE HOST IDENTIFICATION HAS CHANGED!     @  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!  Someone could be eavesdropping on
you right now (man-in-the-middle attack)!  It is also possible that a host key has just been changed.  The fingerprint for the ECDSA key sent by the remote host is
SHA256:jn5ClU5g566Gsvobf8Xc45DJnIiAllN+RJkg35Nf9KE.  Please contact your system administrator.  Add correct host key in /home/me/.ssh/known_hosts to get rid of this message.  Offending ECDSA key
in /home/me/.ssh/known_hosts:19    remove with:    ssh-keygen -f "/home/me/.ssh/known_hosts" -R "[127.0.0.1]:2231"  ECDSA host key for [127.0.0.1]:2231 has changed and you have requested strict
checking.  Host key verification failed.

kafka01 | UNREACHABLE! => {
.....

What's going on here?
Edit: No, I don't want to keep deleting the key.  I destroy/build these over and over again.  I want to find the correct, long-term solution.

**Tags:** ansible, vagrant

> **Comments:**
> **username_1**: `It is also possible that a host key has just been changed.` try to remove the client entry in `/home/me/.ssh/known_hosts`  
> **username_2**: ... by the command proposed in the message `ssh-keygen -f "/home/me/.ssh/known_hosts" -R "[127.0.0.1]:2231`  
> **username_0**: @msp9011 That's the obvious answer, right?  Problem is after I destroy then rebuild the keys have changed again.  I don't want to keep deleting them.  
> **username_0**: @msp9011 only /etc/ansible/  
> **username_1**: can u plz share version of ansible  
> **username_1**: try adding `UserKnownHostsFile=/dev/null` in sshCommonArgs as `ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'  

---

## 1 answers

### Answer by username_3 on 2020-05-06. Score: 5

You can add this in inventory:
ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"

It's ignoring check host and setting /dev/null as Known host file.

> **Comments:**
> **username_4**: Please explain what this will do and remove the spaces at the beginning of the code block  

---

