Skip to content

Instantly share code, notes, and snippets.

@charliemoseley
Created March 2, 2012 00:52
Show Gist options
  • Save charliemoseley/1954378 to your computer and use it in GitHub Desktop.
Save charliemoseley/1954378 to your computer and use it in GitHub Desktop.
Vagrant::Config.run do |config|
###########################################################################
# Multiple VMs config
#
# boot all vms:
# vagrant up
#
# boot specific vm:
# vagrant up services
# vagrant up worker
# vagrant up front
config.vm.define :services do |cfg|
Hark::VM.defaults("Hark Services", cfg)
# cfg.vm.network("33.33.33.22") # Old Syntax
cfg.vm.network :hostonly, "33.33.33.22"
cfg.vm.host_name = "services.hark.local"
cfg.vm.provision :chef_solo do |chef|
Hark::VM.config_chef(chef, "services")
chef.json.merge!({
:server_name => "services.hark.local",
:hark => { :name => 'services' }
})
end
end
config.vm.define :ci do |cfg|
Hark::VM.defaults("Hark CI", cfg)
# cfg.vm.network("33.33.33.23") # Old Syntax
cfg.vm.network :hostonly, "33.33.33.23"
cfg.vm.host_name = "ci.hark.local"
cfg.vm.provision :chef_solo do |chef|
Hark::VM.config_chef(chef, "ci")
chef.json.merge!({
:server_name => "ci.hark.local",
:hark => { :name => 'ci' }
})
end
end
config.vm.define :front do |cfg|
Hark::VM.defaults("Hark Front", cfg)
# cfg.vm.network("33.33.33.21") # Old Syntax
cfg.vm.network :hostonly, "33.33.33.21"
cfg.vm.host_name = "www.hark.local"
cfg.vm.provision :chef_solo do |chef|
Hark::VM.config_chef(chef, "front")
chef.json.merge!({
:server_name => "www.hark.local",
:hark => { :name => 'www' }
})
end
end
config.vm.define :worker do |cfg|
Hark::VM.defaults("Hark Worker", cfg)
# cfg.vm.network("33.33.33.20") # Old Syntax
cfg.vm.network :hostonly, "33.33.33.20"
cfg.vm.host_name = "worker.hark.local"
cfg.vm.provision :chef_solo do |chef|
Hark::VM.config_chef(chef, "worker")
chef.json.merge!({
:server_name => "worker.hark.local",
:hark => { :name => 'worker' }
})
end
end
end
module Hark
module VM
class << self
###########################################################################
# VM defaults for all VMx
def defaults(name, config)
# Old Syntax
#config.vm.customize do |vm|
# vm.memory_size = 512
# vm.name = name
#end
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "hark-lucid-32"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://s3.amazonaws.com/hark/vagrants/hark-lucid-32.box"
# Share an additional folder to the guest VM. The first argument is
# an identifier, the second is the path on the guest to mount the
# folder, and the third is the path on the host to the actual folder.
# config.vm.share_folder "v-data", "/vagrant_data", "../data"
# Boot with a GUI so you can see the screen. (Default is headless)
# config.vm.boot_mode = :gui
config.vm.customize ["modifyvm", :id, "--memory", "512"]
end
###########################################################################
# Enable provisioning with chef solo, specifying a cookbooks path (relative
# to this Vagrantfile), and adding some recipes and/or roles.
def config_chef(chef, role)
chef.log_level = :debug
###########################################################################
# PATHS
chef.roles_path = "roles"
chef.cookbooks_path = "cookbooks"
chef.data_bags_path = "data_bags"
chef.provisioning_path = "/tmp/vagrant-chef"
# if Chef Solo needs its invocation trained further
# chef.binary_env = "GEM_HOME=/opt/rightscale/sandbox/lib/ruby/gems/1.8 GEM_PATH=/opt/rightscale/sandbox/lib/ruby/gems/1.8"
# chef.binary_path = "/opt/rightscale/sandbox/bin/"
###########################################################################
# ROLES
chef.add_role("base")
chef.add_role("local") # staging, production
chef.add_role(role)
###########################################################################
# CONFIG
chef.json.merge!({
:revision => ENV['RELEASE_TAG'] || 'develop'
})
# additional config points beside role files
# chef.add_recipe "mysql"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment