How to initialize known_hosts/authorized_keys/public/private key pairs with ansible

ansibleautomationconfiguration-managementdeployment

I am using ansible to configure and deploy my app on several machines. The only problem I have now is that I am not sure how to properly initialize/automate the very first connection to this machines?

I am getting completely empty machine, so I have to put on this machine at least my public key into authorized_keys, git into known_hosts, as well as private_key for git user(I am using bitbucket). Currently I run small ansible task for every new machine to do all this things.

But I suppose there is more optimal way to do things?

Probably the only solution I see now is to setup single machine and then 'clone' it(I am using digital ocean). But this won't work for env where I am unable to clone images.

Best Answer

I do create the public and private keys on the machine from where Ansible is run. I've got a special init playbook which connects to the servers via password and puts the key files in place. I also found a way for adding the public keys among each other to the authorized_keys file.

The source can be found here: soupdiver/ansible-cluster

Related Topic