# git from github

**URL:** <https://forum.ansible.com/t/git-from-github/13128>\
**Category:** Ansible Project\
**Created:** [July 16, 2013, 12:52am UTC](https://forum.ansible.com/t/git-from-github/13128 "2013-07-16T00:52:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Palmer1](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Eric\_Palmer1](https://forum.ansible.com/u/Eric_Palmer1)\
**Post date:** [July 16, 2013, 12:52am UTC](https://forum.ansible.com/t/git-from-github/13128/1 "2013-07-16T00:52:25Z")

</div>

I want to do a `git archive from git hub private repo or a shallow clone`

`But I don't see how to specify the username and password. If I use the ssh: protocol I can add the username. How do I specify the password.`

`thanks`

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [July 16, 2013, 12:54am UTC](https://forum.ansible.com/t/git-from-github/13128/2 "2013-07-16T00:54:19Z")

</div>

Eric:

I would recommend using ssh agent forwarding to check out a git repo. You’ll need to use the “ssh” connection and enable agent forwarding on your local machine, as well as ensuring that the remote git repo has your ssh public key.

Lorin

---

<div class="post-metadata">

**Author:** ![Eric\_Palmer1](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Eric\_Palmer1](https://forum.ansible.com/u/Eric_Palmer1)\
**Post date:** [July 16, 2013, 12:55am UTC](https://forum.ansible.com/t/git-from-github/13128/3 "2013-07-16T00:55:50Z")

</div>

thanks

I have no idea how to do that but tomorrow I will search google and figure it out. I use mac osx.

thanks

Loving ansible…

Eric

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [July 16, 2013, 1:23am UTC](https://forum.ansible.com/t/git-from-github/13128/4 "2013-07-16T01:23:48Z")

</div>

You’re in luck! Mac OS X has great support for ssh agent forwarding, it automatically starts up an ssh agent for you when you first log in to your machine. You can check it’s running by doing:

echo $SSH\_AUTH\_SOCK

You should see something like:  
/tmp/launch-MYGNdH/Listeners

You’ll need to add “ForwardAgent yes” to your ~/.ssh/config file on your mac.

Lorin

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 16, 2013, 11:44am UTC](https://forum.ansible.com/t/git-from-github/13128/5 "2013-07-16T11:44:59Z")

</div>

Or alternatively you can just specify what key to use to checkout by setting GIT\_SSH via the “environment:” keyword in Ansible.

[http://stackoverflow.com/questions/3496037/how-to-specify-which-ssh-key-to-use-within-git-for-git-push-in-order-to-have-git](http://stackoverflow.com/questions/3496037/how-to-specify-which-ssh-key-to-use-within-git-for-git-push-in-order-to-have-git)

---

<div class="post-metadata">

**Author:** ![Daniel\_Shapiro](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@Daniel\_Shapiro](https://forum.ansible.com/u/Daniel_Shapiro)\
**Post date:** [August 8, 2013, 10:09pm UTC](https://forum.ansible.com/t/git-from-github/13128/6 "2013-08-08T22:09:14Z")

</div>

Hi Lorin,

I’m trying to set this up exactly as you describe, but have not had any luck unfortunately ☹

My ~/.ssh/config works fine when I use ssh manually - I can type “ssh my\_host\_shortname” and connect to my machine and then I can pull from github because I have ForwardAgent properly set.

But I’ve seen zero evidence that ansible is using any information in ~/.ssh/config

Here’s my ansible inventory file: [http://pastebin.com/6e7Ue2VA](http://pastebin.com/6e7Ue2VA)

I can run “ansible all -m ping” and it works fine, but if I run “ansible all -a ‘ssh -T [git@github.com](mailto:git@github.com)’” then I get a permission denied error because my ssh agent was not forwarded.

Any ideas?

Thank you!

- Daniel

---

<div class="post-metadata">

**Author:** ![Rodney\_Quillo](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Rodney\_Quillo](https://forum.ansible.com/u/Rodney_Quillo)\
**Post date:** [August 9, 2013, 7:53am UTC](https://forum.ansible.com/t/git-from-github/13128/7 "2013-08-09T07:53:52Z")

</div>

For ansible, ssh-add to load ssh keys in your host machine first.  
Then use “ssh” as connection type with forwarding enabled.

Such as:  
$ ssh-add

$ export ANSIBLE\_TRANSPORT=“ssh”  
$ export ANSIBLE\_SSH\_ARGS=“-o ForwardAgent=yes”

See manual for ssh-add for running the agent.

Rodney

---

<div class="post-metadata">

**Author:** ![Daniel\_Shapiro](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@Daniel\_Shapiro](https://forum.ansible.com/u/Daniel_Shapiro)\
**Post date:** [August 9, 2013, 3:34pm UTC](https://forum.ansible.com/t/git-from-github/13128/8 "2013-08-09T15:34:34Z")

</div>

Adding ANSIBLE\_SSH\_ARGS=“-o ForwardAgent=yes” worked!

Why did ANSIBLE\_SSH\_ARGS=“-A” not work? That’s the option I use when using the normal ssh command line…

Finally - is there a way I can add this to my config file so that I don’t have to have an environment variable set?

I tried adding this to /etc/ansible/ansible.cfg:

[defaults]  
ansible\_ssh\_args=“-o ForwardAgent=yes”

But now I get this error when connecting:

**[ec2-54-xxx-43-201.us-west-2.compute.amazonaws.com](http://ec2-54-xxx-43-201.us-west-2.compute.amazonaws.com) | FAILED =\> failed to transfer file to /command:**

**command-line: line 0: Bad configuration option: ControlPersist**  
**lost connection**

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![danrough](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/danrough/32/3541_2.png) [@danrough](https://forum.ansible.com/u/danrough)\
**Post date:** [November 6, 2013, 5:06pm UTC](https://forum.ansible.com/t/git-from-github/13128/9 "2013-11-06T17:06:01Z")

</div>

Hey all,

Pardon the thread resurrection but I have a related question.

I wonder if you would have the time to expand it a little for me? I’m attempting to get our Continuous Integration / Deployment system, Strider to run an Ansible playbook to deploy our application. The deploy process will run as a user, Ansible. As part of the deployment process it attempts to grab the latest from a private github repository.

At the moment, I’m attempting to do that using the following:

git: “[repo=git@github.com](mailto:repo=git@github.com):Username/private\_repo.git dest={{ tempdir.stdout }} depth=1”$  
environment:$  
GIT\_SSH: /home/ansible/deployment\_key$

That is failing though and reading out the entire key. I’ve looked at this post ([http://stackoverflow.com/questions/3496037/how-to-specify-which-ssh-key-to-use-within-git-for-git-push-in-order-to-have-git](http://stackoverflow.com/questions/3496037/how-to-specify-which-ssh-key-to-use-within-git-for-git-push-in-order-to-have-git)) on Stackoverflow and can’t work out how to integrate the suggested solution.

Any suggestions?

Thanks, Dan.

---

<div class="post-metadata">

**Author:** ![Jasdeep\_Singh](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@Jasdeep\_Singh](https://forum.ansible.com/u/Jasdeep_Singh)\
**Post date:** [December 8, 2013, 3:40am UTC](https://forum.ansible.com/t/git-from-github/13128/10 "2013-12-08T03:40:35Z")

</div>

SWEEEEETTTT! This worked for me too! Anyway I can add this to my ansible.cfg permanently?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 8, 2013, 3:55pm UTC](https://forum.ansible.com/t/git-from-github/13128/11 "2013-12-08T15:55:31Z")

</div>

Yep, see [http://ansibleworks.com/docs/intro\_configuration.html#ssh-args](http://ansibleworks.com/docs/intro_configuration.html#ssh-args)
