I am trying to do multi machine provision using vagrant with chef-solo . once I apply "vagrant up " command , my web recipe applyed to both vm1 and vm2 . similarly , others recipe get applyed to both VMs . But , I want only web recipe should be applied to VM1 and others recipe to VM2. I am using chef-solo 12.3.0 .
my vagrant file is
Vagrant.configure("2") do |config|
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "pram::web"
config.vm.define :vm1 do |server1|
server1.vm.box = "ubuntu14"
server1.vm.network :private_network, ip: "192.168.102.101"
end
end
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "pram::others"
config.vm.define :vm2 do |server2|
server2.vm.box = "ubuntu14"
server2.vm.network :private_network, ip: "192.168.102.102"
end
end
end
Yes , i got the solution of this problem . in 2nd line of code there should server1 instead of config. server1.vm.provision :chef_solo do |chef| and this block of code should come under VM1 block . similarly , in 10th line it should be server2.vm.provision :chef_solo do |chef| . otherwise given recipes will apply to all VMs that come under config block. correct solution is given below .
end