我正在使用有安排条款的流浪汉。当我从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中将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
答案 0 :(得分:1)
我敢打赌,Ansible不会使用您的配置进行SSH密钥转发(ForwardAgent是)。
可能的建议解决方法是创建特定于部署的密钥,使用Ansible在部署目标中设置它们,然后使用这些密钥进行克隆。