1

I am trying to create and then provision a multi-machine vagrant environment using ansible.

My Vagrant file looks like:

# -*- 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|
    # All Vagrant configuration is done here. The most common configuration
    # options are documented and commented below. For a complete reference,
    # please see the online documentation at vagrantup.com.

    config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"

    (1..3).each do |i|
        config.vm.define "db#{i}" do |node|
            node.vm.box = "trusty64"
            node.vm.network "public_network", ip: "192.168.253.20#{i}", bridge: 'en0: Wi-Fi (AirPort)'
            node.vm.provider "virtualbox" do |v|
                v.customize ["modifyvm", :id, "--memory", 512]
                v.name = "db#{i}_box"
                v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
                v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
            end
        end
    end

    (1..1).each do |i|
        config.vm.define "es#{i}" do |node|
            node.vm.box = "trusty64"
            node.vm.network "public_network", ip: "192.168.253.21#{i}", bridge: 'en0: Wi-Fi (AirPort)'
            node.vm.provider "virtualbox" do |v|
                v.customize ["modifyvm", :id, "--memory", 1024]
                v.name = "es#{i}_box"
                v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
                v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
            end
        end
    end

    config.vm.define "emailchecker" do |node|
        node.vm.box = "trusty64"
        node.vm.network "public_network", ip: "192.168.253.205", bridge: 'en0: Wi-Fi (AirPort)'
        node.vm.provider "virtualbox" do |v|
            v.customize ["modifyvm", :id, "--memory", 1024]
            v.name = "emailchecker_box"
            v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
            v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
        end
    end

    config.vm.define "smartrouter" do |node|
        node.vm.box = "trusty64"
        node.vm.network "public_network", ip: "192.168.253.206", bridge: 'en0: Wi-Fi (AirPort)'
        node.vm.provider "virtualbox" do |v|
            v.customize ["modifyvm", :id, "--memory", 1024]
            v.name = "smartrouter_box"
            v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
            v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
        end
    end


    config.vm.define "web" do |node|
        node.vm.box = "trusty64"
        node.vm.network "public_network", ip: "192.168.253.204", bridge: 'en0: Wi-Fi (AirPort)'
    node.vm.provider "virtualbox" do |v|
            v.customize ["modifyvm", :id, "--memory", 1024]
            v.name = "web_box"
            v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
            v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
        end

        ####
        #
        # Note Provisioning is included here to ensure it only gets run once on all the boxes.
        #
        ####
        node.vm.provision "ansible" do |ansible|
            ansible.playbook = "ansible_playbook/playbook.yml"
            ansible.verbose = "vvvv"
            ansible.limit = 'all'
            ansible.inventory_path = "ansible_playbook/vagrant_inventory"
    end
  end

end

I can create the machines by doing a vagrant up --no-provision and I can log into the machines by doing vagrant ssh web (for example).

However, when I try and provision the machines, I get the following error message:

fatal: [web] => SSH encountered an unknown error. The output was:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/smcgurk/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: auto-mux: Trying existing master
debug1: Control socket "/Users/smcgurk/.ansible/cp/ansible-ssh-192.168.253.204-22-vagrant" does not exist

Has anyone any idea as to what might be going on here or suggestions about how I debug/ remedy this?

Thanks,

Seán

Seán
  • 523
  • 2
  • 10
  • 17
  • does it work if you try to provision the machines one by one ? e.g. vagrant provision web ? I suspect there might be a conflict in the ssh port assigned on the multiple vm – Frederic Henri Oct 02 '15 at 09:37
  • Hmmm... still the same issue: `TASK: [hostfile | deploy hosts for vagrant] *********************************** FATAL: no hosts matched or all hosts have already failed -- aborting PLAY RECAP ******************************************************************** to retry, use: --limit @/Users/smcgurk/playbook.retry web : ok=0 changed=0 unreachable=1 failed=0` But thanks for the suggestion @FrédéricHenri – Seán Oct 02 '15 at 12:28
  • Root cause exactly the same as thisL http://stackoverflow.com/questions/28471542/cant-ssh-to-vagrant-vms-using-the-insecure-private-key-vagrant-1-7-2 – Seán Oct 06 '15 at 10:13

1 Answers1

1

I have seen this error before and its usually down to spaces!

It seems that when the path to the SSH key contains spaces, these are not correctly escaped, effectively breaking Ansible.

I may be totally off the beaten track here but I have rechecked vagrant files in the past and found this to be the case.

Another thought, if you have any references to localhost instead of 127.0.0.1

Andrew
  • 26
  • 3
  • Are you sure vagrant up are bringing both web and db up. In a multi machine setup such as yours, you may need to vagrant up web and vagrant up db, similarly vagrant ssh web and vagrant ssh db.. [https://docs.vagrantup.com/v2/multi-machine/](https://docs.vagrantup.com/v2/multi-machine/) – Andrew Oct 02 '15 at 16:17