Vagrant ansible git clone 权限错误

3
我正在使用带有Ansible provision的Vagrant。当我使用Ansible进行git克隆时,我遇到了以下错误:
failed: [default] => {"cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "rc": 128}
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

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

但是每当我试图手动从Vagrant框中克隆时,它都可以正常工作。我已经搜索了网络,并且在Vagrant中将ssh转发设置为true,我的~/.ssh/config如下,这允许从主机转发。
Host            *
  ForwardAgent  yes

我的ansible yml文件如下:

---
- hosts: all
  sudo: true
  tasks:
    - name: Clone project
      git: repo=<git ssh link>
           accept_hostkey=yes
           clone=yes
           dest=/home/vagrant

我的 Vagrant 文件如下:

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "forwarded_port", guest: 80, host: 9000
  config.vm.provision :ansible do |ansible|
    ansible.playbook = "playbook.yml"
  end
  config.ssh.forward_agent = true
end

每当我从ansible中进行git clone时,为什么会运行以下命令而不是git clone命令:
/usr/bin/git ls-remote '' -h refs/heads/HEAD
1个回答

1
我的猜测是Ansible在您的配置中没有使用SSH密钥转发(ForwardAgent yes)。
可能的建议解决方法是创建特定于部署的密钥,使用Ansible将它们设置到部署目标中,然后使用这些密钥进行克隆。
例如:https://dev59.com/610a5IYBdhLWcg3w-8_a#29727859

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接