# git module with ssh

**URL:** <https://forum.ansible.com/t/git-module-with-ssh/11993>\
**Category:** Ansible Project\
**Created:** [October 17, 2012, 6:28pm UTC](https://forum.ansible.com/t/git-module-with-ssh/11993 "2012-10-17T18:28:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Bassett](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Aaron\_Bassett](https://forum.ansible.com/u/Aaron_Bassett)\
**Post date:** [October 17, 2012, 6:28pm UTC](https://forum.ansible.com/t/git-module-with-ssh/11993/1 "2012-10-17T18:28:41Z")

</div>

Hi, I’m trying to use the ansible and the git module to build a deployment tool for some python code. My git repos are stored on a box we access with ssh keys. I cannot figure out how to get the git module to use my ssh key to access the repo. Currently I’m trying to keep it simple using a simple play with connection:local, but it seems my key is being lost somewhere along the way because I’m getting “Permission denied (publickey).\r\nfatal: The remote end hung up unexpectedly\n.” I can run the git command just fine, but ansible can’t.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 17, 2012, 6:31pm UTC](https://forum.ansible.com/t/git-module-with-ssh/11993/2 "2012-10-17T18:31:20Z")

</div>

It does not presently know how to invoke SSH agent an encrypted key. Patches would be accepted to add a key and password param to the git module.

– Michael

---

<div class="post-metadata">

**Author:** ![Aaron\_Bassett](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Aaron\_Bassett](https://forum.ansible.com/u/Aaron_Bassett)\
**Post date:** [October 17, 2012, 6:51pm UTC](https://forum.ansible.com/t/git-module-with-ssh/11993/3 "2012-10-17T18:51:41Z")

</div>

Mmm I would patch it but it looks like there’s no easy way to tell git which key to use. Easier to just set up your .ssh/config for it as per here: [http://superuser.com/questions/232373/tell-git-which-private-key-to-use](http://superuser.com/questions/232373/tell-git-which-private-key-to-use)

---

<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:** [October 17, 2012, 7:05pm UTC](https://forum.ansible.com/t/git-module-with-ssh/11993/4 "2012-10-17T19:05:12Z")

</div>

We deal with this by using connection=ssh (native ssh connection) with agent forwarding enabled. You’ll need to have ssh-agent running on your local machine and add the key using ssh-add.

To enable agent forwarding in ssh, add the following line in your .ssh/config file:

ForwardAgent yes

Take care,

Lorin

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 17, 2012, 7:32pm UTC](https://forum.ansible.com/t/git-module-with-ssh/11993/5 "2012-10-17T19:32:44Z")

</div>

I still like the idea of adding it to the module. No bootstrapping, far easier… Maybe also do username plus password…

– Michael

---

<div class="post-metadata">

**Author:** ![Stijn\_Opheide](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@Stijn\_Opheide](https://forum.ansible.com/u/Stijn_Opheide)\
**Post date:** [November 5, 2012, 5:19pm UTC](https://forum.ansible.com/t/git-module-with-ssh/11993/6 "2012-11-05T17:19:36Z")

</div>

Hi Xianzhe,

are you sudoing through your playbook? if so, you’ll need to setup /etc/sudoers to keep your SSH\_AUTH\_SOCK environment variable.

cheers,  
Stijn.

---

<div class="post-metadata">

**Author:** ![Xianzhe\_Liang](https://avatars.discourse-cdn.com/v4/letter/x/e19b73/32.png) [@Xianzhe\_Liang](https://forum.ansible.com/u/Xianzhe_Liang)\
**Post date:** [November 6, 2012, 4:35am UTC](https://forum.ansible.com/t/git-module-with-ssh/11993/7 "2012-11-06T04:35:07Z")

</div>

Hi Stijn, Thanks for the quick reply. Yes, adding SSH\_AUTH\_SOCK makes it work!

Best,  
Xianzhe
