# git module hangs on clone with ansible-playbook, but works for ansible with same arguments

**URL:** <https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094>\
**Category:** Ansible Project\
**Created:** [November 17, 2012, 11:42pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094 "2012-11-17T23:42:52Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![nflacco](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nflacco](https://forum.ansible.com/u/nflacco)\
**Post date:** [November 17, 2012, 11:42pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/1 "2012-11-17T23:42:52Z")

</div>

I’m having trouble with the git module. It works via ansible but not ansible playbook. The arguments are exactly the same. I can ssh into the server and do a git clone from the command line in the target folder as well. Does ansible-playbook require different params for the git module?

**Ansible**

> $ansible prod --user=ec2-user --private-key=key.pem -m git -a ‘repo=git@bitbucket.org:nflacco/myrepo.git dest=/srv/checkout/myrepo’  
> [www.myserver.com](http://www.myserver.com) | success \>\> {  
> “after”: “3c50d2b”,  
> “before”: null,  
> “changed”: true  
> }

**Ansible-playbook (playbook file)**

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [November 18, 2012, 11:53am UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/2 "2012-11-18T11:53:04Z")

</div>

> I’m having trouble with the git module. It works via ansible but not ansible playbook. The arguments are exactly the same. I can ssh into the server and do a git clone from the command line in the target folder as well. Does ansible-playbook require different params for the git module?
> 
> **Ansible**
> 
> > $ansible prod --user=ec2-user --private-key=key.pem -m git -a ‘repo=git@bitbucket.org:nflacco/myrepo.git dest=/srv/checkout/myrepo’  
> > [www.myserver.com](http://www.myserver.com) | success \>\> {  
> > “after”: “3c50d2b”,  
> > “before”: null,  
> > “changed”: true  
> > }
> 
> **Ansible-playbook (playbook file)**
> 
> * * *
> 
> - hosts: prod  
> sudo: True  
> vars:  
> node\_version: “0.6.13”  
> tasks:
> - name: Install Git  
> action: yum pkg=git state=latest
> - name: Get myrepo  
> action: git [repo=git@bitbucket.org](mailto:repo=git@bitbucket.org):nflacco/myrepo.git dest=/srv/checkout/myrepo
> 
> Here is the command line output (with verbose), after I manually stop it because it hangs ad infinium:
> 
> > TASK: [Install Git] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> > ok: [[www.myserver.com](http://www.myserver.com)] =\> {“changed”: false, “msg”: “”, “rc”: 0, “results”: [“All packages providing git are up to date”]}  
> > TASK: [Get myrepo] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> > ^C32  
> > ERROR: interupted
> 
> When I use more than the stub playbook above (copy git ssh keys and bunch of other stuff), ansible-playbook creates an empty folder (with .git subfolder) and hangs.

+1 for me, I noticed that same behaviour with ansible-playbook. Didn’t test with plain ansible though.

---

<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:** [November 18, 2012, 3:17pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/3 "2012-11-18T15:17:20Z")

</div>

It's exactly the same module.

You may be seeing issues with repeated executions.

---

<div class="post-metadata">

**Author:** ![nflacco](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nflacco](https://forum.ansible.com/u/nflacco)\
**Post date:** [November 18, 2012, 7:47pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/4 "2012-11-18T19:47:00Z")

</div>

Repeated executions? I can execute the ansible command over and over, but the playbook one doesn’t work from the start, apart from a creating the destination folder and .git subfolder.

With a clean destination the ansible command works great. The folder appears in the destination.

> $ansible prod --user=ec2-user --private-key=key.pem -m git -a ‘repo=git@bitbucket.org:nflacco/myrepo.git dest=/srv/checkout/myrepo’  
> [www.myserver.com](http://www.myserver.com) | success \>\> {  
> “after”: “3c50d2b”,  
> “before”: null,  
> “changed”: true  
> }

I executed it 3 more times and observed the destination folder- no changes as there were no new commits, but it worked fine.

> $ansible prod --user=ec2-user --private-key=key.pem -m git -a ‘repo=git@bitbucket.org:nflacco/myrepo.git dest=/srv/checkout/myrepo’  
> [www.myserver.com](http://www.myserver.com) | success \>\> {  
> “after”: “3c50d2b”,  
> “before”: “3c50d2b”,  
> “changed”: false  
> }

I then pushed a commit and the change went through on the destination folder, and the ansible output reflected that:

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [November 19, 2012, 11:34am UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/5 "2012-11-19T11:34:45Z")

</div>

Some more info from my side:

When using the git module to deploy ansible from github, no problem.  
When jusing the git module to deploy/update out ansible data repository, it hangs.

Looking at our internal “git server”, I see these processes, all sleeping:

root 4799 0.0 0.7 73496 3764 ? Ss 12:28 0:00 \_ sshd: root@pts/3  
root 4814 0.0 0.1 12776 756 ? Ss 12:28 0:00 \_ /usr/lib/openssh/sftp-server  
root 4815 0.0 0.1 4400 612 pts/3 Ss+ 12:28 0:00 \_ /bin/sh -c /usr/bin/python /root/.ansible/tmp/ansible-1353324504.07-33812526893647/git  
root 4816 0.1 1.4 37780 7120 pts/3 S+ 12:28 0:00 \_ /usr/bin/python /root/.ansible/tmp/ansible-1353324504.07-33812526893647/git  
root 4817 0.0 0.1 4400 612 pts/3 S+ 12:28 0:00 \_ /bin/sh -c git clone -o acd ssh://git@svn-pr-1-mgt/~git/ansible-data.git /opt/ansible/data  
root 4818 0.0 0.2 15236 1340 pts/3 S+ 12:28 0:00 \_ git clone -o acd ssh://git@svn-pr-1-mgt/~git/ansible-data.git /opt/ansible/data  
root 4819 0.0 0.5 43528 2924 pts/3 S+ 12:28 0:00 \_ ssh git@svn-pr-1-mgt git-upload-pack ‘~git/ansible-data.git’

When I manually issue the git clone command on the ansible deployed host:

git clone -o acd ssh://git@svn-pr-1-mgt/~git/ansible-data.git /opt/ansible/data

That works without a problem!

Could this be some weird behaviour caused by the ansible python “wrappers”?

Serge

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [November 19, 2012, 11:37am UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/6 "2012-11-19T11:37:30Z")

</div>

Initially, the git target directory was empty.  
And after this manual clone, re-running the play yields:

root 5409 0.0 0.7 73496 3756 ? Ss 12:35 0:00 \_ sshd: root@pts/3  
root 5424 0.0 0.1 12776 756 ? Ss 12:35 0:00 \_ /usr/lib/openssh/sftp-server  
root 5425 0.0 0.1 4400 612 pts/3 Ss+ 12:35 0:00 \_ /bin/sh -c /usr/bin/python /root/.ansible/tmp/ansible-1353324934.89-62485605234825/git  
root 5426 0.4 1.4 37780 7120 pts/3 S+ 12:35 0:00 \_ /usr/bin/python /root/.ansible/tmp/ansible-1353324934.89-62485605234825/git  
root 5435 0.0 0.1 4400 612 pts/3 S+ 12:35 0:00 \_ /bin/sh -c git fetch acd  
root 5436 0.0 0.2 15412 1264 pts/3 S+ 12:35 0:00 \_ git fetch acd  
root 5437 0.0 0.5 43528 2924 pts/3 S+ 12:35 0:00 \_ ssh git@svn-pr-1-mgt git-upload-pack ‘~git/ansible-data.git’

on the git ‘server’, and hangs similarly.

Serge

---

<div class="post-metadata">

**Author:** ![Stephen\_Fromm](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Stephen\_Fromm](https://forum.ansible.com/u/Stephen_Fromm)\
**Post date:** [November 19, 2012, 10:38pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/7 "2012-11-19T22:38:48Z")

</div>

Based on the above, it appears you are using the git module with different  
users. Can you confirm? If so, are both users set up with the same ssh  
key to access the git repo via ssh?

It appears, based on your ps listing in a subsequent email, that ssh is  
hanging on something. Is the ssh key password protected? Is ssh-agent, or  
some similar mechanism, already running? Have you tried strace'ing that  
process to see what it is waiting on?

sf

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [November 20, 2012, 10:58am UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/8 "2012-11-20T10:58:47Z")

</div>

Hi Stephen,

> Based on the above, it appears you are using the git module with different users. Can you confirm? If so, are both users set up with the same ssh key to access the git repo via ssh?

I’m not sure based on what you conclude this. Ansible-playbook runs from a local user on my machine and connects with root on the target machine.

> It appears, based on your ps listing in a subsequent email, that ssh is hanging on something. Is the ssh key password protected? Is ssh-agent, or some similar mechanism, already running? Have you tried strace’ing that process to see what it is waiting on?

The target machine has a ssh key managed by keychain which permits it to log on the “git ssh server” (with user git).

This must be my issue: the ansible runner isn’t aware of the keychain environment as it doesn’t load the shell environment, which is a problem on my side of course, not an ansible problem.

Serge

---

<div class="post-metadata">

**Author:** ![gewin](https://avatars.discourse-cdn.com/v4/letter/g/96bed5/32.png) [@gewin](https://forum.ansible.com/u/gewin)\
**Post date:** [December 30, 2012, 10:26pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/9 "2012-12-30T22:26:10Z")

</div>

Same issue here. I messed around with it for a few hours but ultimately chose to put ansible commands into a batch file instead of using a playbook. Works fine that way.

---

<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:** [February 26, 2013, 6:42pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/10 "2013-02-26T18:42:35Z")

</div>

output of "ansible --version" please

---

<div class="post-metadata">

**Author:** ![damon\_ciarelli](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@damon\_ciarelli](https://forum.ansible.com/u/damon_ciarelli)\
**Post date:** [February 27, 2013, 6:38pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/11 "2013-02-27T18:38:48Z")

</div>

_bash-3.2$ ansible --version_  
_ansible 1.0_

I got past this yesterday but I was just able to reproduce the problem on a fresh instance.

by killing the “ssh [git@github.com](mailto:git@github.com) git-upload-pack” process while it was hanging, the problem reveals itself to be that the git server is not a known host…

_"RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48._  
_Are you sure you want to continue connecting (yes/no)?"_  
at which point git ( and everything else) hangs.

I guess the workaround would be to add your git server to .ssh/known\_hosts before firing off the git module.

Oh…haha… and now that I was just looking to see if there was an Ansible “known\_hosts” module ala the one for authorized\_keys, I notice this exact issue is mentioned in the [documentation for the HG module](http://ansible.cc/docs/modules.html#hg). Perhaps it can be added to the docs for Git.

Just for the record, even with this trouble on my first experience with Ansible, I was so impressed that I didn’t abandon it even after hours of dealing with this issue.  
Thanks to the makers!

---

<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:** [February 27, 2013, 8:40pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/12 "2013-02-27T20:40:43Z")

</div>

That needs to be me in the git module docs under 'notes'.

Someone please send me a patch.

If there are git flags to ignore this, it would be very nice to add  
them, but it's a little tricky over ssh:// transport

I imagine lots of people will also be doing deployments over git://  
and http:// when the goal of the deployment is not to create a  
development environment.

---

<div class="post-metadata">

**Author:** ![donald\_lee](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@donald\_lee](https://forum.ansible.com/u/donald_lee)\
**Post date:** [June 8, 2013, 7:31pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/13 "2013-06-08T19:31:21Z")

</div>

Piggybacking off this thread as it seems related.So, I’m new to ansible, and i have been trying to clone a private repo onto my webserver by doing the following task:

“- name: Copy Coursehack from git to webserver  
action: git repo=[https://github.com/sherifnosseir/Coursehack.git](https://github.com/sherifnosseir/Coursehack.git) dest=/var/www/Coursehack  
tags: deploy”

This would run and hang for a bit and return to me with an error. Specifically,

failed: [[coursehack.org](http://coursehack.org/)] =\> {“cmd”: [“/usr/bin/git”, “clone”, “-o”, “origin”, “[https://github.com/sherifnosseir/Coursehack.git](https://github.com/sherifnosseir/Coursehack.git)”, “/var/www/Coursehack”], “failed”: true, “rc”: 128}  
stderr: error: Couldn’t resolve host ‘[github.com](http://github.com/)’ while accessing [https://github.com/sherifnosseir/Coursehack.git/info/refs](https://github.com/sherifnosseir/Coursehack.git/info/refs)  
fatal: HTTP request failed

stdout: Cloning into ‘/var/www/Coursehack’…

msg: error: Couldn’t resolve host ‘[github.com](http://github.com/)’ while accessing [https://github.com/sherifnosseir/Coursehack.git/info/refs](https://github.com/sherifnosseir/Coursehack.git/info/refs)  
fatal: HTTP request failed

FATAL: all hosts have already failed – aborting

Now, has anybody else ran into this issue and does anyone have a resolution to this matter?

Thank you,  
Donald

---

<div class="post-metadata">

**Author:** ![damon\_ciarelli](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@damon\_ciarelli](https://forum.ansible.com/u/damon_ciarelli)\
**Post date:** [June 8, 2013, 7:49pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/14 "2013-06-08T19:49:08Z")

</div>

What happens if you ssh into the machine and “ping [github.com](http://github.com)”. ?

---

<div class="post-metadata">

**Author:** ![donald\_lee](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@donald\_lee](https://forum.ansible.com/u/donald_lee)\
**Post date:** [June 11, 2013, 11:09pm UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/15 "2013-06-11T23:09:40Z")

</div>

Hi Damon,

Thanks for responding.

I get “ping: unknown host [github.com](http://github.com)” so it seems like i’m getting the same problem that you had.  
I’m not super familiar with all this key, known hosts, and authenticating stuff (raises hand when asked for noob)  
so if possible can you give me a play by play on how you solved your problem?

I am assuming I would need to copy the id\_rsa/id\_rsa.pub file from my local machine (which i use to authenticate  
with my private repo) to the server, so that i could clone from my server.

Thanks for all your help!

---

<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:** [June 12, 2013, 1:45am UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/16 "2013-06-12T01:45:48Z")

</div>

Donald:

The error messages you are getting suggest that it is a DNS issue, not an SSH authentication issue. Can you show us the contents of the /etc/resolv.conf file on the remote machine?

Lorin

---

<div class="post-metadata">

**Author:** ![donald\_lee](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@donald\_lee](https://forum.ansible.com/u/donald_lee)\
**Post date:** [June 12, 2013, 2:16am UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/17 "2013-06-12T02:16:17Z")

</div>

Hi Lorin,

The resolve.conf file is empty. I am currently fiddling around with ansible and vagrant. Following this tutorial: [https://github.com/leucos/ansible-tuto/tree/master/step-01](https://github.com/leucos/ansible-tuto/tree/master/step-01) I’ve managed to set up a LAMP server with the host file containing

“[coursehack.org](http://coursehack.org) ansible\_ssh\_host=192.168.33.11 ansible\_ssh\_user=root”

Thank you very much for your help sir,

Donald

---

<div class="post-metadata">

**Author:** ![Tanner\_Semerad1](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@Tanner\_Semerad1](https://forum.ansible.com/u/Tanner_Semerad1)\
**Post date:** [January 23, 2014, 1:02am UTC](https://forum.ansible.com/t/git-module-hangs-on-clone-with-ansible-playbook-but-works-for-ansible-with-same-arguments/12094/18 "2014-01-23T01:02:23Z")

</div>

For anyone still having this issue, I fixed it by listing the repo in HTTP format rather than SSH - [http://mysite.com/mygitrepo.git](http://mysite.com/mygitrepo.git) instead of [git@mysite.com](mailto:git@mysite.com):mygitrepo.git
