Skip to content

Instantly share code, notes, and snippets.

@StephenKing
Last active December 17, 2015 09:19
Show Gist options
  • Save StephenKing/5586885 to your computer and use it in GitHub Desktop.
Save StephenKing/5586885 to your computer and use it in GitHub Desktop.
My Vagrantfile
boxes = [
{
:name => :default,
:ip => '192.168.156.130',
:run_list => '',
# :http_port => '8080',
# :gui => true,
# :memory => 2048,
# :cpus => 4,
},
# { :name => :example2, :run_list => 'role[example]', :ip => '192.168.156.131' },
]
Vagrant.configure("2") do |config|
# VAGRANT_BOX (like all the other ENV['...']) is an environment variable,
# which can be set for the current shell session via
# $ export VAGRANT_BOX=wheezy
# or can be added to your shell profile (e.g. ~/.bash_profile)
base_box = ENV['VAGRANT_BOX'] || "wheezy"
domain = ENV['VAGRANT_DOMAIN'] || "vagrant"
config.vm.box = base_box
config.vm.box_url = "..."
boxes.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.hostname = "%s.#{domain}" % opts[:name].to_s
config.vm.network :private_network, ip: opts[:ip]
config.vm.network :forwarded_port, guest: 80, host: opts[:http_port], id: "http" if opts[:http_port]
config.vm.synced_folder "tmp/apt-cache/#{base_box}/", "/var/cache/apt", :create => true
config.vm.provider :virtualbox do |vbox|
vbox.gui = opts[:gui] || false
memory = opts[:memory] || 512
cpus = opts[:cpus] || 2
vbox.customize ["modifyvm", :id, "--memory", memory]
vbox.customize ["modifyvm", :id, "--cpus", cpus]
vbox.name = "%s.#{domain}" % opts[:name].to_s
end
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
chef.roles_path = ["roles"]
chef.data_bags_path = ["data_bags"]
chef.log_level = ENV['CHEF_LOG_LEVEL'] || :info
# Define common roles
run_list = []
run_list << ['recipe[minitest-handler]']
run_list << ['role[debian]']
run_list << ['role[vagrant]']
run_list << opts[:run_list].split(",") if opts[:run_list]
run_list << ENV['CHEF_RUN_LIST'].split(",") if ENV.has_key?('CHEF_RUN_LIST')
chef.run_list = [run_list].flatten
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment