如何根据inner_foo(array[i])
将vagrant
告诉provision
?我在一个循环下旋转多个虚拟机
condition
:
Vagrantfile
我想添加这样的内容:
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Iterate through entries in YAML file
servers.each do |servers|
config.vm.define servers["name"] do |srv|
srv.vm.hostname = servers["name"] + DOMAIN
srv.vm.box = servers["box"]
srv.vm.network "private_network", ip: servers["ip"]
srv.vm.synced_folder ".", "/data", id: "mapping", disabled: servers["share"]
srv.vm.provider :virtualbox do |vb|
vb.memory = servers["ram"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
end
end
end
但每次在所有VM上执行 servers.each do |servers|
config.vm.define servers["name"] do |srv|
srv.vm.hostname = servers["name"] + DOMAIN
srv.vm.box = servers["box"]
srv.vm.network "private_network", ip: servers["ip"]
srv.vm.synced_folder ".", "/data", id: "mapping", disabled: servers["share"]
srv.vm.provider :virtualbox do |vb|
vb.memory = servers["ram"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
if servers["name"] == "server1"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "#{cookbooks}"
chef.add_recipe "chef_blah::server"
end
else
puts("Skipping it...")
end
end
end
块
答案 0 :(得分:0)
那应该是account
,即您只在该服务器上定义它而不是根Vagrant配置。
答案 1 :(得分:0)
我想我找到了解决方案。这是我的错误
而不是:
config.vm.provision :chef_solo do |chef|
我应该用
srv.vm.provision :chef_solo do |chef|
在srv
循环