Skip to content

Instantly share code, notes, and snippets.

@charlesjohnson
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesjohnson/834651271f61a510586c to your computer and use it in GitHub Desktop.
Save charlesjohnson/834651271f61a510586c to your computer and use it in GitHub Desktop.
Chef Provisioning snippet
# vagrant_driver.rb
require 'chef/provisioning/vagrant_driver'
vagrant_box 'chef/ubuntu-12.04'
with_machine_options :vagrant_options => {
'vm.box' => 'chef/ubuntu-12.04'
}
# Number of webservers we want
num_webservers = 2
# Create our array of hosts, append in as many webservers as we want
hosts = %w(dbserver balancer)
1.upto(num_webservers) do |i|
hosts << "web#{i}"
end
# Loop to build all of our hosts in order, offset at 20 for IP address final octet
hosts.each.with_index(20) do |hostname, ip|
machine hostname do
add_machine_options :vagrant_options => {
'vm.hostname' => "#{hostname}.chef-demo.com"
}, :vagrant_config => <<-EOM
config.vm.network :private_network, ip: '192.168.243.#{ip}'
EOM
chef_environment 'production'
run_list [
'recipe[ohai_plugins::vagrant_ipaddress]',
'role[ubuntu_base]'
]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment