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.