我正在使用 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 进行克隆。
关于git - Vagrant ansible git clone 权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31652210/