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:
1 2 3 4 |
- name: add SSH host key known_hosts: name='myhost.com' key="{{ lookup('file', 'host_key.pub') }}" |
I have copied /etc/ssh/ssh_host_rsa_key.pub to host_key.pub and the file looks like:
1 2 |
ssh-rsa AAAAB3NzaC1... root@myhost.com |
If I run my playbook I always get the following error message:
1 2 3 4 |
TASK: [add SSH host key] ****************************************************** failed: [default] => {"cmd": "/usr/bin/ssh-keygen -F myhost.com -f /tmp/tmpe5KNIW", "failed": true, "rc": 1} |
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:
1 2 |
myhost.com ssh-rsa AAAAB3NzaC1... root@myhost.com |
Reference:
Ansible known_hosts module, specifically the name parameter