rrichards
12/30/2014 - 9:13 PM

Vagrant Multi-Machine configuration

# -*- mode: ruby -*-
# vi: set ft=ruby :
# inspired from https://gist.github.com/dlutzy/2469037

boxes = [
  { :name => :web, ip: '192.168.33.10', ssh_port: 2223 },
  { :name => :db, ip: '192.168.33.11', ssh_port: 2224 },
  { :name => :zookeeper, ip: '192.168.33.12', ssh_port: 2225 },
  { :name => :kafka, ip: '192.168.33.13', ssh_port: 2226 },
  { :name => :storm, ip: '192.168.33.14', ssh_port: 2227 },
  { :name => :elasticsearch, ip: '192.168.33.15', ssh_port: 2228 },
]

CUSTOM_CONFIG = {
                  "BOX_NAME"  =>  "precise64",
                  "BOX_URL"   =>  "http://files.vagrantup.com/precise64.box",
                  "HEADLESS"  =>  false
                }

Vagrant.configure("2") do |config|

  # headless?  uncomment this to have the VM's window available
  config.vm.provider :virtualbox do |vb|
    vb.gui = CUSTOM_CONFIG['HEADLESS']
  end

  # Disable default ssh in order to manually assign to a known value
  # https://github.com/mitchellh/vagrant/issues/3232
  config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true

  boxes.each do |opts|
    config.vm.define opts[:name] do |boxconfig|
      boxconfig.vm.box        = CUSTOM_CONFIG['BOX_NAME']
      boxconfig.vm.box_url    = CUSTOM_CONFIG['BOX_URL']
      boxconfig.vm.hostname   = "%s.vagrant" % opts[:name].to_s
      boxconfig.vm.network      "private_network", ip: opts[:ip]
      boxconfig.vm.network    :forwarded_port, guest: 22, host: opts[:ssh_port]
    end
  end

  # provisioning with ansible
  # config.vm.provision :ansible do |ansible|
  #   ansible.playbook = "./provisioning/site.yml"
  # end

end