I am using vagrant with ansible provision. When I am doing git clone with from ansible I am getting following error:
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
But when ever I am trying to clone from vagrant box manually it works fine. I have searched net and I have got ssh forwarding set to true in vagrant and my ~/.ssh/config looks like following which allows forwarding from host machine.
Host *
ForwardAgent yes
My ansible yml file is as follows:
---
- hosts: all
sudo: true
tasks:
- name: Clone project
git: repo=<git ssh link>
accept_hostkey=yes
clone=yes
dest=/home/vagrant
My Vagrant file is as follows:
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
One more question whenever I am doing git clone from ansible why it runs following command instead of git clone:
/usr/bin/git ls-remote '' -h refs/heads/HEAD
My bet is on that Ansible doesn't do SSH key forwarding (ForwardAgent yes) with your config.
Possible suggested workaround is to create a deployment specific keys, use Ansible to set them up in the deployment target and then use these keys to do the clone.
E.g. https://stackoverflow.com/a/29727859/315168
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With