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

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 | success >> {
“after”: “3c50d2b”,
“before”: null,
“changed”: true
}

Ansible-playbook (playbook file)

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 | 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: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] => {“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.

It's exactly the same module.

You may be seeing issues with repeated executions.

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 | 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 | 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:

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

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

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

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

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.

output of "ansible --version" please

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 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. 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!

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.

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 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] => {“cmd”: [“/usr/bin/git”, “clone”, “-o”, “origin”, “https://github.com/sherifnosseir/Coursehack.git”, “/var/www/Coursehack”], “failed”: true, “rc”: 128}
stderr: error: Couldn’t resolve host ‘github.com’ while accessing 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’ while accessing 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

What happens if you ssh into the machine and “ping github.com”. ?

Hi Damon,

Thanks for responding.

I get “ping: unknown host 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!

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

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 I’ve managed to set up a LAMP server with the host file containing

coursehack.org ansible_ssh_host=192.168.33.11 ansible_ssh_user=root”

Thank you very much for your help sir,

Donald

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