Ansible Push SSH Public key
1 The management of the machine can be directly push the past
Using ssh-keygen-t RSA to generate a key pair,
!miyaoqq20141225124030.png!
Id_rsa the private key, which remains on the host, Id_rsa.pub is the public key that needs to be pushed to the management machine and renamed to the Authorized_keys file
Push to remote machine ssh-copy-id-i ~/.ssh/id_rsa.pub [email protected][ip,hostname]
2 machine Many cases, the use of Ssh-copy-id method some time-consuming, using Ansible-playbook push Ymal, here used to Authoried_keys module, can refer to http://docs.ansible.com/ Authorized_key_module.html
At the same time hosts content
!neirongqq20141225125319.png!
<pre>
[Email protected] ~]# ansible-playbook/etc/ansible/rsync_key.ymal-f 10
</pre>
Appear
<pre>
Error:authorized_key is isn't a legal parameter at this level in an Ansible Playbook
</pre>
may be Ymal language format problem, or rsync_key.ymal problem, in error
Modify Rsync_key.ymal Content
1 # Using Alternate directory locations:
2-hosts:test89
3 User:root
4 tasks:
5-name:ssh-copy
6 Authorized_key:user=cuibo key= "{{lookup (' file ', '/root/.ssh/id_rsa.pub ')}}"
7 Tags:
8-sshkey
Finally, the SSH public key is pushed successfully.
Ansible Push SSH Public key