我正在尝试设置一个在 vagrant box 中克隆 repo 的任务。我已经正确设置了代理转发,在 ~/.ssh/known_hosts 中添加了 repo 服务器,并已验证我可以以 vagrant 用户身份登录并克隆 repo,而无需输入凭据,也不会检查主机密钥(git clone 运行顺利)。
我的任务设置如下:
- name: Check out pname dev branch
git: repo=ssh://[email protected]:dev-team/pname.git
dest=/home/vagrant/pname
version=dev
accept_hostkey=yes
become: yes
become_user: vagrant
我的任务刚刚挂起,详细设置为 -vvvv 会产生以下输出:
<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'"'"''
有没有办法找出阻碍 git clone 任务的原因?
更新:
运行以下任务按预期进行:
- name: Clone project dev branch
shell: git clone [email protected]:dev-team/project.git /home/vagrant/www/project
sudo: false
args:
creates: /home/vagrant/www/project
而以下使用 git 本机任务处理程序失败(不再挂起):
# This task does not work!
- name: Check out project dev branch
git: repo=ssh://[email protected]:dev-team/project.git
dest=/home/vagrant/www/project
accept_hostkey=yes
force=yes
sudo: false
这是显示的错误:
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.
为什么 shell 任务可以工作,而不是本机 git 任务?
答案1
似乎repo
选项中存在语法错误。您是否尝试:
用替换/
?
看看模块文档:
Example just ensuring the repo checkout exists
- git: repo=git://foosball.example.org/path/to/repo.git dest=/srv/checkout update=no
:
即使您使用SSH
协议,Ansible 似乎也不会在 repo URL 中使用。