git - Vagrant ansible git clone 权限错误

标签 git ssh vagrant ansible vagrantfile

我正在使用 vagrant 和 ansible provision。当我使用 ansible 执行 git clone 时,出现以下错误:

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 box 克隆时,它工作正常。我搜索了网络,我在 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

最佳答案

我敢打赌,Ansible 不会使用您的配置进行 SSH key 转发(ForwardAgent 是)。

建议的可能解决方法是创建部署特定 key ,使用 Ansible 在部署目标中设置它们,然后使用这些 key 进行克隆。

例如https://stackoverflow.com/a/29727859/315168

关于git - Vagrant ansible git clone 权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31652210/

相关文章:

ubuntu - 从主机推送文件后,可以在 lxc 容器中找到文件

vagrant - CoreOS:flecttl list-machines 显示错误

android - 将新的 git 添加到 AOSP 存储库中

python - 不 ssh 时文件消失

通过 ssh 进行 mysql 复制 - 失败

shell - 让 ansible 在没有退出代码停止 ssh 连接的情况下运行脚本

docker - 无法安装 Docker - 哈希和不匹配(Ubuntu 18.04、Vagrant、Virtualbox)

git - 配置 Git 以接受特定 https 远程服务器的特定自签名服务器证书

git - 如何让 git 忽略 .gitignore 中的忽略

git - 忘记推送提交