# ansible known\_hosts module failed

**URL:** <https://forum.ansible.com/t/ansible-known-hosts-module-failed/18340>\
**Category:** Ansible Project\
**Created:** [May 29, 2015, 1:18am UTC](https://forum.ansible.com/t/ansible-known-hosts-module-failed/18340 "2015-05-29T01:18:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon\_Xie](https://avatars.discourse-cdn.com/v4/letter/l/5e9695/32.png) [@Leon\_Xie](https://forum.ansible.com/u/Leon_Xie)\
**Post date:** [May 29, 2015, 1:18am UTC](https://forum.ansible.com/t/ansible-known-hosts-module-failed/18340/1 "2015-05-29T01:18:16Z")

</div>

Hi all,

I use the below playbook to add known hosts:

---

<div class="post-metadata">

**Author:** ![Jeff\_Trawick](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@Jeff\_Trawick](https://forum.ansible.com/u/Jeff_Trawick)\
**Post date:** [June 14, 2015, 6:22pm UTC](https://forum.ansible.com/t/ansible-known-hosts-module-failed/18340/2 "2015-06-14T18:22:40Z")

</div>

The format of the key has to be in the form that it appears in a known\_hosts file. So ssh to the target system, verify and accept the key, then take the line added to your local known\_hosts file and add that.

---

<div class="post-metadata">

**Author:** ![Ulrich\_Hochholdinger](https://avatars.discourse-cdn.com/v4/letter/u/839c29/32.png) [@Ulrich\_Hochholdinger](https://forum.ansible.com/u/Ulrich_Hochholdinger)\
**Post date:** [June 14, 2015, 10:37pm UTC](https://forum.ansible.com/t/ansible-known-hosts-module-failed/18340/3 "2015-06-14T22:37:52Z")

</div>

Hi,  
The known\_hosts module expects a complete “known\_hosts - line” as key value. The public key from /etc/ssh lists no hostname. So in your example the correct behaviour can be achieved by preceding the hostname:

Example:  
…

- name: known\_hosts  
known\_hosts: path=“/home/xiaoliang/.ssh/known\_hosts” host=“sun1-db-1” state=present

key=“sun1-db-1 {{ lookup(‘file’, ‘/tmp/keys/[10.223.0.51/etc/ssh/ssh\_host\_rsa\_key.pub](http://10.223.0.51/etc/ssh/ssh_host_rsa_key.pub)’) }}”  
…

Cheers  
Ulli
