Provisioning with a git task on vagrant + ansible doesn't appear to be working, guessing the problem is ssh-forwarding.
If I ssh into the box, I can git clone
just fine. I can look with ssh-add -L
and see my key has indeed been forwarded.
When I run vagrant provision
though, I get:
failed: [ss_app] => {"changed": false, "cmd": "/usr/bin/git ls-remote git@github.com:org/app.git -h refs/heads/master", "failed": true, "item": "", "rc": 128}
stderr: Permission denied (publickey).
fatal: The remote end hung up unexpectedly
On the task:
- name: install from git
git: >
repo={{ app.repo }}
dest={{ app.home }}
version={{ app.version }}
accept_hostkey=yes
update=yes
With this in my ansible.cfg
:
[defaults]
transport = ssh
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes -A
I've also tried using:
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provision.yml"
ansible.inventory_path = "hosts/vagrant"
ansible.sudo = true
ansible.host_key_checking = false
ansible.verbose = 'vvvv'
ansible.extra_vars = {
ansible_ssh_user: 'vagrant',
ansible_connection: 'ssh',
ansible_ssh_args: '-o ForwardAgent=yes'
}
end
Per some other stack overflow questions. None of these work, though.
Thoughts?
Edit:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provision.yml"
ansible.inventory_path = "hosts/vagrant"
ansible.sudo = true
ansible.host_key_checking = false
ansible.verbose = 'vvvv'
ansible.extra_vars = {
ansible_ssh_user: 'vagrant',
ansible_connection: 'ssh',
ansible_ssh_args: '-o ForwardAgent=yes -A'
}
# ansible.limit = 'all'
end
config.ssh.forward_agent = true
config.vm.define :ss_app do |ss_app_config|
ss_app_config.vm.box = "precise64"
ss_app_config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
ss_app_config.vm.network :private_network, ip: "10.1.100.100"
ss_app_config.vm.network :forwarded_port, guest: 22, host: 2222, id: 'ssh', auto_correct: true
ss_app_config.ssh.forward_agent = true
ss_app_config.vm.provider :virtualbox do |virtualbox|
virtualbox.customize ["modifyvm", :id, "--memory", "1024"]
end
end
end
^^ There's more of my Vagrantfile.
And here's the command being run: /usr/bin/git ls-remote git@github.com:org/app.git -h refs/heads/master
If I login via vagrant ssh
then run that command, it works fine, only fails during the provision.