我正在尝试使用Ansible和Vagrant设置开发环境。现在我卡在了从Bitbucket克隆Git仓库的步骤。
以下是Vagrantfile和Ansible设置以及我尝试过的事情。
在我的Vagrantfile中,我有config.ssh.forward_agent = true
在我的deploy.yml中:
- name: ensure bitbucket is a known host
lineinfile:
dest: /home/vagrant/.ssh/known_hosts
create: yes
state: present
line: "{{ lookup('pipe', 'ssh-keyscan -p 443 -t rsa altssh.bitbucket.org') }}"
regexp: "^altssh\\.bitbucket\\.org"
sudo_user: "vagrant"
tags: known_hosts
- name: checkout opentest repo
git: >
dest="/home/vagrant/ot/"
repo="ssh://git@altssh.bitbucket.org:443/muhammadammar/opentest/"
version="master"
accept_hostkey=yes
sudo_user: "vagrant"
tags: checkout
首先,您需要将Bitbucket的公钥添加到/home/vagrant/.ssh/known_hosts
中。
当Ansible尝试从存储库检出时,以下是输出内容:
<127.0.0.1> ESTABLISH CONNECTION FOR USER: vagrant
<127.0.0.1> REMOTE_MODULE git dest="/home/vagrant/ot/" repo="ssh:********@altssh.bitbucket.org:443/muhammadammar/opentest/" version=master accept_hostkey=yes
<127.0.0.1> EXEC ssh -C -vvv -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/ammar/.ansible/cp/%h-%r" -o StrictHostKeyChecking=no -o Port=2222 -o IdentityFile="/Users/ammar/.vagrant.d/insecure_private_key" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 127.0.0.1 /bin/sh -c 'sudo -k && sudo -HE -S -p "[sudo via ansible, key=vwkfotuvzzmllxvxptkgehjzdlqygoez] password: " -u vagrant /bin/sh -c '"'"'echo BECOME-SUCCESS-vwkfotuvzzmllxvxptkgehjzdlqygoez; LANG=C LC_CTYPE=C /usr/bin/python'"'"''
failed: [default] => {"cmd": "/usr/bin/git ls-remote 'ssh:********@altssh.bitbucket.org:443/muhammadammar/opentest/' -h refs/heads/master", "failed": true, "rc": 128}
stderr: RSA host key for IP address '131.103.20.174' not in list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
msg: RSA host key for IP address '131.103.20.174' not in list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
FATAL: all hosts have already failed -- aborting
to retry, use: --limit @/Users/ammar/dev.retry
default : ok=1 changed=0 unreachable=0 failed=1
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
在我的主机上,我已经将我的私钥添加到ssh认证代理中。我可以在主机和vagrant box上使用
ssh-add -l
查看私钥身份。在vagrant box中,我可以成功地使用
git clone ssh://git@altssh.bitbucket.org:443/muhammadammar/opentest ot
克隆repo。我不确定问题出在哪里。有人可以帮助解决这个问题吗? 编辑 即使在ansible中以下内容也无法工作。
shell: "git clone ssh://git@altssh.bitbucket.org:443/muhammadammar/opentest/ /home/vagrant/omp/"