Skip to content
This repository has been archived by the owner on Apr 4, 2018. It is now read-only.

Commit

Permalink
Vagrant nodes with different IPs and RAM
Browse files Browse the repository at this point in the history
Demonstrate assigning private network interfaces to VMs, in order for them
to communicate with each other. And assigning a different amount of RAM to a
single node. Nodes are defined in a Ruby hash.

VirtualBox provider customisations have been moved into the `nodes.each`
loop because it needs access to `node_opts[:memory]`. There seems to be no
speed impact to `vagrant status`. Whereas calling `customize` twice would
have been significantly slower, even if it did look cleaner.
  • Loading branch information
dcarley committed Jun 12, 2013
1 parent 7aafc6f commit 39837ac
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions Vagrantfile
@@ -1,29 +1,40 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

nodes = %w{node0 node1 node2}
nodes = {
'node0' => {:ip => '172.16.10.1', :memory => 512},
'node1' => {:ip => '172.16.10.2'},
'node2' => {:ip => '172.16.10.3'},
}

Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"

config.vm.provider :virtualbox do |vb|
modifyvm_args = ['modifyvm', :id]
# Isolate guests from host networking.
modifyvm_args << "--natdnsproxy1" << "on"
modifyvm_args << "--natdnshostresolver1" << "on"
vb.customize(modifyvm_args)
end

config.vm.provision :puppet do |puppet|
puppet.manifest_file = "site.pp"
puppet.manifests_path = "manifests"
puppet.module_path = [ "modules", "vendor/modules" ]
end

nodes.each do |node_name|
nodes.each do |node_name, node_opts|
config.vm.define node_name do |node|
node.vm.hostname = node_name

if node_opts[:ip]
node.vm.network(:private_network, :ip => node_opts[:ip])
end

config.vm.provider :virtualbox do |vb|
modifyvm_args = ['modifyvm', :id]
if node_opts[:memory]
modifyvm_args << "--memory" << node_opts[:memory]
end
# Isolate guests from host networking.
modifyvm_args << "--natdnsproxy1" << "on"
modifyvm_args << "--natdnshostresolver1" << "on"
vb.customize(modifyvm_args)
end
end
end
end

0 comments on commit 39837ac

Please sign in to comment.