How to add a host to the known_host file with ansible?

Question:

I want to add the ssh key for my private git server to the known_hosts file with ansible 1.9.3 but it doesn’t work.

I have the following entry in my playbook:

I have copied /etc/ssh/ssh_host_rsa_key.pub to host_key.pub and the file looks like:

If I run my playbook I always get the following error message:

What I am doing wrong?

Answer:

Your copy of the remote host public key needs a name, that name needs to match what you specify for your known hosts.

In your case, prepend "myhost.com " to your host_key.pub key file as follows:

Reference:
Ansible known_hosts module, specifically the name parameter

Leave a Reply