如何在Vagrant中为多机环境指定配置器默认值?

And*_*inn 7 vagrant vagrantfile

我想知道在使用Vagrant创建多机环境时是否有办法为配置程序指定默认值?

我试图做类似以下的事情:

Vagrant.configure("2") do |config|
  config.vm.box = "andyshinn/ubuntu-precise64"

  config.vm.provision :chef_client do |chef|
    chef.chef_server_url = "https://api.opscode.com/organizations/myorg"
    chef.validation_key_path = "~/.chef/myorg-validator.pem"
    chef.delete_node = true
    chef.delete_client = true
    chef.validation_client_name = "myorg-validator"
  end

  config.vm.define :app do |app|
    app.vm.network "private_network", ip: "172.16.64.61"
    app.vm.host_name = "vagrant-app-#{ENV['USER']}"

    app.vm.provision :chef_client do |chef|
      chef.add_recipe "myrecipe1"
      chef.add_recipe "myrecipe2"
      chef.add_recipe "sudo"
    end
  end

  config.vm.define :web do |web|
    web.vm.network "private_network", ip: "172.16.64.62"
    web.vm.host_name = "vagrant-web-#{ENV['USER']}"

    web.vm.provision :chef_client do |chef|
      chef.add_recipe "myrecipe3"
      chef.add_recipe "myrecipe4"
      chef.add_recipe "sudo"
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

但是每个VM块似乎都没有获取任何主配置块设置.我收到此错误:

There are errors in the configuration of this machine. Please fix
the following errors and try again:

chef client provisioner:
* Chef server URL must be populated.
* Validation key path must be valid path to your chef server validation key.
Run Code Online (Sandbox Code Playgroud)

可以通过另一种方法?

Luk*_*ino 0

也许您已经可以使用此功能,但如果没有,请检查以下内容:

它部分解决了我的问题;也许它会对你有帮助。