Skip to content

Instantly share code, notes, and snippets.

@house9
Created June 1, 2013 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save house9/5690784 to your computer and use it in GitHub Desktop.
Save house9/5690784 to your computer and use it in GitHub Desktop.
Vagrantfile that sets up multiple boxes and loads chef configuration
Vagrant.configure("2") do |config|
# assumes your chef.json files are in cookbooks or site-cookbooks directory
servers = [
{
id: :db1,
ip: "172.16.2.111",
node_json: "master-db.json"
},
{
id: :db2,
ip: "172.16.2.222",
node_json: "standby-db.json"
},
{
id: :web1,
ip: "172.16.2.333",
node_json: "web.json"
}
]
# for testing remove some servers from provision
db_servers.reject! { |item| item[:id] == :db2 }
db_servers.each do |server_settings|
config.vm.define server_settings[:id] do |db|
db.vm.box = "precise32"
db.vm.network :private_network, ip: server_settings[:ip]
db.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"]
# http://jbbarth.com/posts/2011-03-20-vagrant-provisioning-with-chefsolo.html
["./nodes/#{server_settings[:node_json]}"].each do |node_file|
json = JSON.parse(File.read(node_file))
json["run_list"].each { |run| chef.add_recipe(run) }
chef.json.merge!(json)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment