Member-only story
Ansible Clone Private Git Repository
2 min readJun 30, 2021
To clone private repository from Github you have to add your public ssh key to Github and your private ssh key should be present on your local machine. Problem with Ansible configured servers is that they don’t have your ssh private key so you can’t clone private repository there.
There are couple of methods to solve this problem.
- Copy your ssh private key to Ansible server. This approach is not recommended because it will leave your private ssh key at multiple places and that is very bad for obvious security reason.
- Generate ssh key for you Ansible server and add your public key to your Github profile automatically via Github Access Token REST API. Like Asif Mahmud did in his article Clone Private Git Repository using Ansible. This method is useful if you are using another machine as Ansible Control Node. If you are using your personal machine as Ansible Control Node then this method is over kill for you since there is a much simpler method called SSH agent forwarding which let you to clone private git repositories.
- SSH agent forwarding allows you to use your private, local SSH key remotely without worrying about leaving confidential data on the server you’re working with. It’s built into
ssh
, and is easy to set up and use. And we would use it here. You can read more about SSH agent forwarding on this…