【问题标题】:Error With Vagrant ProvisioningVagrant 配置错误
【发布时间】:2015-10-02 09:10:11
【问题描述】:

我正在尝试使用 ansible 创建并配置多机流浪环境。

我的 Vagrant 文件如下所示:

# -*- 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

结束

我可以通过 vagrant up --no-provision 来创建机器,我可以通过 vagrant ssh web 登录到机器(例如)。

但是,当我尝试配置机器时,我收到以下错误消息:

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

有没有人知道这里可能会发生什么或关于我如何调试/解决这个问题的建议?

谢谢,

肖恩

【问题讨论】:

  • 如果您尝试一台一台地配置机器,它是否有效?例如流浪者提供网?我怀疑在多个 vm 上分配的 ssh 端口可能存在冲突
  • 嗯...仍然是同样的问题: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 但感谢@FrédéricHenri 的建议
  • 根本原因和thisL一模一样*.com/questions/28471542/…

标签: vagrant ansible provisioning vagrantfile


【解决方案1】:

我以前见过这个错误,它通常归结为空格!

似乎当 SSH 密钥的路径包含空格时,这些空格没有正确转义,有效地破坏了 Ansible。

我可能在这里完全脱离了人迹罕至的地方,但我过去重新检查了 vagrant 文件并发现情况确实如此。

另一个想法,如果您对 localhost 而不是 127.0.0.1 有任何引用

【讨论】:

  • 你确定 vagrant up 会同时启动 web 和 db。在像您这样的多机设置中,您可能需要 vagrant up web 和 vagrant up db,类似地 vagrant ssh web 和 vagrant ssh db .. https://docs.vagrantup.com/v2/multi-machine/