How to specify default backup options in Vagrant for multi-machine environments?

I am wondering if there is a way to specify default values ​​for conductors when creating a layered environment using Vagrant?

I tried to do something like the following:

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 

But each VM block does not seem to pick up any of the basic settings of the configuration block. I get this error:

 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. 

Perhaps using another method?

+7
vagrant vagrantfile
source share
3 answers

You may already have this work, but if not, check this out:

He partially solved my problem; perhaps this will help you.

0
source share

Your problem is one area. The chef variable has a block area in the config.vm.provision do block.

As soon as this block leaves your changes, it will disappear. You should follow the example in multi-machine docs on a roaming site.

config.vm.provision "shell", inline: "echo Hello"

 Vagrant.configure("2") do |config| config.vm.box = "andyshinn/ubuntu-precise64" config.vm.provision "chef_client", chef_server_url: "https://api.opscode.com/organizations/myorg" config.vm.provision "chef_client", validation_key_path: "~/.chef/myorg-validator.pem config.vm.provision "chef_client", delete_node: true config.vm.provision "chef_client", delete_client: true config.vm.provision "chef_client", validation_client_name: "myorg-validator" 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 

Gotta do the trick

+1
source share

I think that the inner block "overrides" the outer one. You can, however, do something like what I did in my answer (to my own question) to fake the highest ordering of providers , and not from the outside, as Vagrant provides, In your case, you would not have a shell and puppet like mine, but you would use something like a boilerplate method to expand on a chef with more recipes. Maybe something like:

 module Vagrant module Config module V2 class Root def provision(extra_recipes) 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" extra_recipes.each { |recipe| chef.add_recipe(recipe) } end end end end end end Vagrant.configure("2") do |config| config.vm.box = "andyshinn/ubuntu-precise64" 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.provision("myrecipe1", "myrecipe2", "sudo") 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']}" app.provision("myrecipe3", "myrecipe4", "sudo") end end 
0
source share

All Articles