Technotes

Technotes for future me

Cloning private GitHub repositories with Ansible on a remote server through SSH

Cloning private GitHub repositories with Ansible on a remote server through SSH

Using SSH Agent

First, add the following SSH configuration to your ~/.ssh/config file:

Host [server-address-here] [ip-address-here]
    ForwardAgent yes

This enables forwarding keys loaded into ssh-agent to remote SSH connections.

Check which keys are loaded currently using ssh-add -l,
and add any additional required keys using ssh-add ~/.ssh/key-here.

The next time you run the Git task in your playbook, you should see something like:

TASK [geerlingguy.role : Clone a private repository into /opt.] *******************************************  
changed: [server]  

Any time you run the Ansible playbook (or ad hoc tasks),
the Ansible’s SSH connection will hold all the loaded SSH Agent keys,
so you can perform private Git repository operations without tasks failing.

https://www.jeffgeerling.com/blog/2018/cloning-private-github-repositories-ansible-on-remote-server-through-ssh

Last updated on 31 Jan 2021
Published on 11 Dec 2019
Edit on GitHub