How do I use remote machine’s SSH keys in ansible git module

Question:

I’ve been trying to get Ansible to provision a remote machine, and I want the remote machine to be set up with its own keys, and have the ability to clone git repositories from Bitbucket.

The user is set up, has its own id_rsa.pub, and the key has been registered with bitbucket.

But, when I use the Ansible Git module, it looks like the module always tries to use the keys from the machine running the playbook.

How do I get the git module to use the id_rsa.pub from the remote machine?

The relevant task is this:

The relevant inventory is this

Answer:

This is how I deploy from Github using a key file set on the remote server. If the keyfile parameter for git doesn’t work then something is wrong with your playbook:

Leave a Reply