# known\_hosts case issue

**URL:** <https://forum.ansible.com/t/known-hosts-case-issue/20769>\
**Category:** Ansible Project\
**Created:** [March 4, 2016, 10:45am UTC](https://forum.ansible.com/t/known-hosts-case-issue/20769 "2016-03-04T10:45:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Morgan](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan](https://forum.ansible.com/u/James_Morgan)\
**Post date:** [March 4, 2016, 10:45am UTC](https://forum.ansible.com/t/known-hosts-case-issue/20769/1 "2016-03-04T10:45:53Z")

</div>

Hi,

Has anybody come across this issue with the known\_hosts module.

The hostname of the box is uppercase. When I ssh to the box and add to the known\_hosts file it gets added lowercase

> `<br>[root@SPOBKJJUMPBOX ansible]# ssh SPOBKJLOGSVR<br>`  
>   
> |
> 
> - |  
>   
>   
> `<br>The authenticity of host 'spobkjlogsvr (10.XXXXX.202)' can't be established.<br>`  
>   
> |  
>   
>   
> `<br>RSA key fingerprint is f8:09:f5:8d:31:5f:3f:dd:74:28:f8:af:be:3f:16:cb.<br>`  
>   
> |  
>   
>   
> `<br>Are you sure you want to continue connecting (yes/no)? yes<br>`  
>   
> |  
>   
>   
> `<br>Warning: Permanently added 'spobkjlogsvr,10.XXXXX.202' (RSA) to the list of known hosts.<br>`  
>   
> |

Using the known\_hosts module I was using

local\_action:  
module: known\_hosts  
name: “{{ ansible\_fqdn }}”  
key: “{{ ansible\_fqdn }},{{ ansible\_default\_ipv4.address }} ssh-rsa {{ ansible\_ssh\_host\_key\_rsa\_public }}”

to add each servers public rsa key to the jump boxes known hosts file. This fails

TASK: [openbet/user-obadmin | Add server key to known hosts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

2016-03-04 18:08:31 (task 0h 0m 0.019s, total 0h 0m 4.102s)  
\<127.0.0.1\> REMOTE\_MODULE known\_hosts key=‘SPOBKJLOGSVR ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAv5iU809JBGNiBSbH3TpmYh4h1ww+j9Mdxo3ZJDeFtqOUNob0YSPWwit1AruQqB/o1kXKERgACEMvS/plW6ywjdiCkwG+IvFiBeudgNlNlds8orpK227mdugpozDYUepacDKLrcKpvPbzPgJwijQLtWQefk+RbcncuMQJM6CmKgGUOk5z+9IuZBd6hfK1iPba/fU0QT+eZ7LwXp5sORdlfRyazG7FuyTckXtC0KXUjA43KUqUCq3LnVhofxg3BbFGAjW3LxL1qVptRduwxcPIZDQ==’ name=SPOBKJLOGSVR  
failed: [SPOBKJLOGSVR → 127.0.0.1] =\> {“failed”: true}  
msg: Host parameter does not match hashed host field in supplied key

The error comes from the sanity check where Ansible runs **ssh-keygen -F host**

/usr/lib/python2.6/site-packages/ansible/modules/extras/system/known\_hosts.py

try:  
outf=tempfile.NamedTemporaryFile()  
outf.write(key)  
outf.flush()  
except IOError,e:  
module.fail\_json(msg=“Failed to write to temporary file %s: %s” %   
(outf.name,str(e)))  
rc,stdout,stderr=module.run\_command([sshkeygen,‘-F’,host,  
‘-f’,outf.name], check\_rc=True)

This uses the uppercase hostname SPOBKJLOGSVR. ssh-keygen doesn’t match and therefore returns blank and fails.

Should this be case insensitive. I could use lowecase hostname though these seems the wrong approach.

Any ideas?

Many thanks James

---

<div class="post-metadata">

**Author:** ![James\_Morgan](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan](https://forum.ansible.com/u/James_Morgan)\
**Post date:** [March 4, 2016, 10:48am UTC](https://forum.ansible.com/t/known-hosts-case-issue/20769/2 "2016-03-04T10:48:15Z")

</div>

I should add this is Ansible 1.9.4
