# 'Unknown host key error' only happens when running a playbook

**URL:** <https://forum.ansible.com/t/unknown-host-key-error-only-happens-when-running-a-playbook/31101>\
**Category:** Ansible Project\
**Created:** [August 22, 2019, 1:46pm UTC](https://forum.ansible.com/t/unknown-host-key-error-only-happens-when-running-a-playbook/31101 "2019-08-22T13:46:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauricio\_Tavares](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mauricio\_Tavares](https://forum.ansible.com/u/Mauricio_Tavares)\
**Post date:** [August 22, 2019, 1:46pm UTC](https://forum.ansible.com/t/unknown-host-key-error-only-happens-when-running-a-playbook/31101/1 "2019-08-22T13:46:20Z")

</div>

So I want to reach out to my router. I first try

raub@desktop:~/dev/ansible$ ssh janitor@uranus.example.com  
janitor@uranus. example.com's password:

which is expected since I have ssh'd into the router quite many times  
from this computer. i.e. by now it knows uranus quite well. Just to be  
paranoid, let's try port 830 as this is a Juniper router:

raub@desktop:~/dev/ansible$ ssh -p 830 janitor@uranus.mgmt.kushana.com  
janitor@uranus.mgmt.kushana.com's password:

So far so good. Then I run a quick ansible test:

raub@desktop:~/dev/ansible$ ansible-playbook -vvv network.yml --limit uranus  
[...]  
ok: [uranus] =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"changed": false,  
&nbsp;&nbsp;&nbsp;&nbsp;"elapsed": 0,  
&nbsp;&nbsp;&nbsp;&nbsp;"invocation": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"module\_args": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"active\_connection\_states": [  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ESTABLISHED",  
&nbsp;&nbsp;&nbsp;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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"path": null,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"port": 830,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"search\_regex": null,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"sleep": 1,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"state": "started",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"timeout": 300  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;},  
&nbsp;&nbsp;&nbsp;&nbsp;"match\_groupdict": {},  
&nbsp;&nbsp;&nbsp;&nbsp;"match\_groups": ,  
&nbsp;&nbsp;&nbsp;&nbsp;"path": null,  
&nbsp;&nbsp;&nbsp;&nbsp;"port": 830,  
&nbsp;&nbsp;&nbsp;&nbsp;"search\_regex": null,  
&nbsp;&nbsp;&nbsp;&nbsp;"state": "started"  
}

TASK [network : Get facts about "uranus"]

---

<div class="post-metadata">

**Author:** ![Zolvaring](https://avatars.discourse-cdn.com/v4/letter/z/ce73a5/32.png) [@Zolvaring](https://forum.ansible.com/u/Zolvaring)\
**Post date:** [August 22, 2019, 7:31pm UTC](https://forum.ansible.com/t/unknown-host-key-error-only-happens-when-running-a-playbook/31101/2 "2019-08-22T19:31:43Z")

</div>

I don't know why the Ansible playbook would respond differently to the host key unless it's not running as the same user that you ssh with, so someone else will hopefully answer that but what I can suggest if you're willing to forego host key checking you can run the play with 'export ANSIBLE\_HOST\_KEY\_CHECKING=False', there is also an option for this you can set in the configuration file. Obviously you can also try ssh-keyscan and see if the host keys are different from your known hosts file, but the env var will skip that check altogether (obvious security implications)

---

<div class="post-metadata">

**Author:** ![Mauricio\_Tavares](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mauricio\_Tavares](https://forum.ansible.com/u/Mauricio_Tavares)\
**Post date:** [August 22, 2019, 7:35pm UTC](https://forum.ansible.com/t/unknown-host-key-error-only-happens-when-running-a-playbook/31101/3 "2019-08-22T19:35:32Z")

</div>

> I don't know why the Ansible playbook would respond differently to the host key unless it's not running as the same user that you ssh with, so someone else will hopefully answer that but what I can suggest if you're willing to forego host key checking you can run the play with 'export ANSIBLE\_HOST\_KEY\_CHECKING=False', there is also an option for this you can set in the configuration file. Obviously you can also try ssh-keyscan and see if the host keys are different from your known hosts file, but the env var will skip that check altogether (obvious security implications)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;What I have been doing for now is running it as

ANSIBLE\_HOST\_KEY\_CHECKING=False ansible-playbook -vvv network.yml --limit uranus

which is still not what I want to do but it is slightly better than  
just exporting the variable for all to fondle.

---

<div class="post-metadata">

**Author:** ![Wawrzek\_Niewodniczan](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@Wawrzek\_Niewodniczan](https://forum.ansible.com/u/Wawrzek_Niewodniczan)\
**Post date:** [August 23, 2019, 7:35am UTC](https://forum.ansible.com/t/unknown-host-key-error-only-happens-when-running-a-playbook/31101/4 "2019-08-23T07:35:43Z")

</div>

[...]

Anything special (any user definition) in hosts file and/or playbook?  
Maybe, it is related to netconf  
([https://docs.ansible.com/ansible/latest/plugins/connection/netconf.html](https://docs.ansible.com/ansible/latest/plugins/connection/netconf.html))?

Wawrzek
