2015-09-28 380 views
3

我正在尝试使用ansible和vagrant设置开发环境。现在我坚持从bitbucket克隆git repo。ansible git clone权限被拒绝问题

下面是Vagrantfile和可靠的设置以及我尝试过的东西。

在我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://[email protected]:443/muhammadammar/opentest/" 
    version="master" 
    accept_hostkey=yes 
    sudo_user: "vagrant" 
    tags: checkout 

第一任务添加到位桶的公钥到/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认证代理。我可以在主机和流浪盒上看到使用ssh-add -l的私钥身份。

在颠沛流离的盒子,我可以成功地克隆使用git clone ssh://[email protected]:443/muhammadammar/opentest ot

我不知道是什么问题回购。任何人都可以帮助解决这个问题。

编辑

即使下面不ansible

shell: "git clone ssh://[email protected]:443/muhammadammar/opentest/ /home/vagrant/omp/" 
+0

您是否尝试了http://stackoverflow.com/a/30775053/4296747的建议? –

+0

@FrédéricHenri无法正常工作 – MA1

回答

1

能工作,对流浪的盒子成功运行git clone ...是不够的。

的方式我认为,正在发生的事情是:

  • ansible试图打开一个SSH连接流浪汉箱为用户“流浪者”(User=vagrant),并提供身份文件:-o IdentityFile="/Users/ammar/.vagrant.d/insecure_private_key"
  • 执行/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'"'"'
  • 试图git clone使用用户 '********'(ssh:********@altssh.bitbucket.org:443/...)

哟你应该可以这样做,是你吗?

如果不是,那么原因可以是许多例如

  • /Users/ammar/.vagrant.d/insecure_private_key对于用户vagrant不是正确的文件。
  • vagrant不是一个sudoer。 /以上所有步骤输出
  • [email protected]用户的密钥不********@altssh.bitbucket.org

注册你会知道你已经通过日志看了之后正确的原因。

PS:使用sudo_user: vagrant似乎是多余的,如果您已经在使用同一个用户执行ssh的话。我可以想出为什么可以这样做的一些原因,但至少在这里是多余的。

+0

感谢您的回复,但不幸的是,我不知道上面的任何内容,因为这是我第一次寻找安全和流浪。我从来没有想过,为git操作正确配置vagrant box是复杂的,需要关于很多设置的知识。 – MA1

+0

@ MA1 :-)总有第一次.. – Kashyap

0

我有同样的问题。你的脚本中是否使用“sudo:yes”?如果你是,那么根用户需要访问回购站,而不是流浪用户。

将root用户的公钥文件添加到Bitbucket帐户,你应该没问题。

或者,您可以通过普通用户进行结账。

在任何情况下,访问vagrant内repo的用户的公钥都需要能够访问Bitbucket。