3

I am trying to setup a task that clones a repo in a vagrant box. I have setup agent forwarding properly, added the repo server in ~/.ssh/known_hosts, and have validated I can log in as vagrant user and clone the repo without being asked for credentials and host key is not checked ( git clone runs without a hitch ).

My task is set up as follows:

- name: Check out pname dev branch
  git: repo=ssh://git@gitlab.dev-web.ca:dev-team/pname.git
    dest=/home/vagrant/pname
    version=dev
    accept_hostkey=yes
  become: yes
  become_user: vagrant

My task just hangs, verbose set to -vvvv gives the following output:

<10.210.55.82> ESTABLISH CONNECTION FOR USER: vagrant
<10.210.55.82> REMOTE_MODULE git repo=ssh:********@dev-web.ca:dev-team/project.git dest=/home/vagrant/project_folder version=dev accept_hostkey=yes
<10.210.55.82> EXEC ssh -C -tt -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/stef/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=22 -o IdentityFile="/Users/stef/devbox_cp/.vagrant/machines/default/parallels/private_key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 10.210.55.82 /bin/sh -c 'mkdir -p /tmp/ansible-tmp-1449685034.66-224282565675976 && chmod a+rx /tmp/ansible-tmp-1449685034.66-224282565675976 && echo /tmp/ansible-tmp-1449685034.66-224282565675976'
<10.210.55.82> PUT /var/folders/q1/21hlrxsd4y1_hr8n5kx4cq540000gn/T/tmp8KpkMe TO /tmp/ansible-tmp-1449685034.66-224282565675976/git
<10.210.55.82> EXEC ssh -C -tt -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/stef/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=22 -o IdentityFile="/Users/stef/devbox_cp/.vagrant/machines/default/parallels/private_key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 10.210.55.82 /bin/sh -c 'chmod a+r /tmp/ansible-tmp-1449685034.66-224282565675976/git'
<10.210.55.82> EXEC ssh -C -tt -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/stef/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=22 -o IdentityFile="/Users/stef/devbox_cp/.vagrant/machines/default/parallels/private_key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 10.211.55.82 /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=fhtkrnevvknmiinzxxqzrvyofblvkzhi] password: " -u vagrant /bin/sh -c '"'"'echo BECOME-SUCCESS-fhtkrnevvknmiinzxxqzrvyofblvkzhi; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1449685034.66-224282565675976/git'"'"'' 

Is there a way to figure out what is holding up the git clone task?

Update:

Running the following task works as expected:

- name: Clone project dev branch
  shell: git clone git@gitlab.dev-web.ca:dev-team/project.git /home/vagrant/www/project
  sudo: false
  args:
 creates: /home/vagrant/www/project

While the following, using git native task handler fails (does not hang anymore):

# This task does not work!
- name: Check out project dev branch
  git: repo=ssh://git@gitlab.dev-web.ca:dev-team/project.git
       dest=/home/vagrant/www/project
       accept_hostkey=yes
       force=yes
  sudo: false

This is the error that is shown:

failed: [default] => {"cmd": "/usr/bin/git ls-remote 'ssh:********@gitlab.cgi-web.ca:dev-team/project.git' -h refs/heads/HEAD", "failed": true, "rc": 128}
stderr: GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.

Why would the shell task work, versus the native git task?

stefgosselin
  • 257
  • 1
  • 4
  • 14

1 Answers1

5

It seems like you got an syntax error in the repo option. Did you try replacing : with /?

Take a look at the module documentation:

Example just ensuring the repo checkout exists
- git: repo=git://foosball.example.org/path/to/repo.git dest=/srv/checkout update=no

Ansible does not seem to use : in repo URLs even when you use SSH protocol.

Henrik Pingel
  • 9,380
  • 2
  • 28
  • 39