Ansible + passwordstore: Creating, storing and distributing SSH key pairs
There are many situations where you need or want to use SSH keys for connecting to a server. This could be automatic software deployment (continuous deployment) or backup.
I was looking for a way to create, securely store and distribute the necessary keys to my server for both deployment and backup purposes. I was already using Ansible for setup up my servers. So it was obvious to use it for the SSH keys too. My goal was to
- check if we have the wanted key pair in the password store
- create a new key pair, if we don't have it in the password store
- save the newly created key pair in the password store
- deploy the necessary key to the server
only by running a playbook.
I created a gist with the solution I came up with.