This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Resources
No comments:
Post a Comment