Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible SSH forwarding doesn't seem to work with Vagrant

Tags:

OK, strange question. I have SSH forwarding working with Vagrant. But I'm trying to get it working when using Ansible as a Vagrant provisioner.

I found out exactly what Ansible is executing, and tried it myself from the command line, sure enough, it fails there too.

[/common/picsolve-ansible/u12.04%]ssh -o HostName=127.0.0.1 \  -o User=vagrant -o  Port=2222 -o UserKnownHostsFile=/dev/null \  -o StrictHostKeyChecking=no -o PasswordAuthentication=no \  -o IdentityFile=/Users/bryanhunt/.vagrant.d/insecure_private_key \  -o IdentitiesOnly=yes -o LogLevel=FATAL \  -o ForwardAgent=yes "/bin/sh  \  -c 'git clone [email protected]:bryan_picsolve/poc_docker.git /home/vagrant/poc_docker' " Permission denied (publickey,password). 

But when I just run vagrant ssh the agent forwarding works correctly, and I can checkout R/W my github project.

[/common/picsolve-ansible/u12.04%]vagrant ssh vagrant@vagrant-ubuntu-precise-64:~$ /bin/sh  -c 'git clone [email protected]:bryan_picsolve/poc_docker.git /home/vagrant/poc_docker' Cloning into '/home/vagrant/poc_docker'... remote: Counting objects: 18, done. remote: Compressing objects: 100% (14/14), done. remote: Total 18 (delta 4), reused 0 (delta 0) Receiving objects: 100% (18/18), done. Resolving deltas: 100% (4/4), done. vagrant@vagrant-ubuntu-precise-64:~$ 

Has anyone got any idea how it is working?

Update:

By means of ps awux I determined the exact command being executed by Vagrant.

I replicated it and git checkout worked.

 ssh [email protected] -p 2222 \   -o Compression=yes \   -o StrictHostKeyChecking=no \   -o LogLevel=FATAL \    -o StrictHostKeyChecking=no \   -o UserKnownHostsFile=/dev/null \   -o IdentitiesOnly=yes \   -i /Users/bryanhunt/.vagrant.d/insecure_private_key \   -o ForwardAgent=yes \   -o LogLevel=DEBUG \    "/bin/sh  -c 'git clone [email protected]:bryan_picsolve/poc_docker.git /home/vagrant/poc_docker' " 
like image 376
binarytemple_picsolve Avatar asked Jan 06 '14 14:01

binarytemple_picsolve


People also ask

Can I use Ansible provisioner with vagrant to manage one machine?

This is covered in detail in the Vagrant documentation, but here is a quick example that includes a section to use the Ansible provisioner to manage a single machine: # This guide is optimized for Vagrant 1.8 and above. # Older versions of Vagrant put less info in the inventory they generate.

How do I create an ansible inventory file in Vagrant?

With our Vagrantfile example, Vagrant automatically creates an Ansible inventory file in .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory. This inventory is configured according to the SSH tunnel that Vagrant automatically creates.

How to manage a single machine with Vagrant?

The first step once you’ve installed Vagrant is to create a Vagrantfile and customize it to suit your needs. This is covered in detail in the Vagrant documentation, but here is a quick example that includes a section to use the Ansible provisioner to manage a single machine: # This guide is optimized for Vagrant 1.8 and above.

How do I run Ansible manually?

If you want to run Ansible manually, you will want to make sure to pass ansible or ansible-playbook commands the correct arguments, at least for the inventory. The “Tips and Tricks” chapter of the Ansible Provisioner documentation provides detailed information about more advanced Ansible features like:


1 Answers

As of ansible 1.5 (devel aa2d6e47f0) last updated 2014/03/24 14:23:18 (GMT +100) and Vagrant 1.5.1 this now works.

My Vagrant configuration contains the following:

config.vm.provision "ansible" do |ansible|    ansible.playbook = "../playbooks/basho_bench.yml"    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'} 

It is also a good idea to explicitly disable sudo use. For example, when using the Ansible git module, I do this:

- name: checkout basho_bench repository    sudo: no   action: git [email protected]:basho/basho_bench.git dest=basho_bench 
like image 80
binarytemple_picsolve Avatar answered Sep 19 '22 17:09

binarytemple_picsolve