Last active
December 16, 2015 17:29
-
-
Save enricopulatzo/5470626 to your computer and use it in GitHub Desktop.
My vagrantfile for provisioning multiple boxes privately networked provisioned by puppet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby sts=2 ts=2 expandtab sw=2: | |
Vagrant.configure("2") do |config| | |
puppet_nodes = [ | |
{ | |
:hostname => 'clusternode', | |
:ip => '192.168.2.202', | |
:ram => 1024 | |
}, | |
{ | |
:hostname => 'gfdomain', | |
:ip => '192.168.2.50', | |
:fwdports => [ | |
:guest => 4848, :host => 4848 | |
], | |
:ram => 1024 | |
} | |
] | |
# craft a hosts file based on localhost plus the above nodes so that we can access our private network automatically | |
$hosts = [] | |
puppet_nodes.each do |node| | |
$hosts << node[:ip] + " " + node[:hostname] | |
end | |
$overwrite_hosts_script = <<SCRIPT | |
echo "127.0.0.1 localhost">/etc/hosts | |
SCRIPT | |
$hosts.each do |line| | |
$overwrite_hosts_script += <<SCRIPT | |
echo "#{line}" >> /etc/hosts | |
SCRIPT | |
end | |
config.vm.box = "fedora-18-puppet" | |
# for each puppet node, set it up and provision it via puppet with a manifest | |
# corresponding to its hostname | |
puppet_nodes.each do |node| | |
config.vm.define node[:hostname] do |cfg| | |
if node[:box] && node[:box_url] | |
cfg.vm.box = node[:box] | |
cfg.vm.box_url = node[:box_url] | |
end | |
cfg.vm.hostname = node[:hostname] | |
cfg.vm.network :private_network, :ip => node[:ip] | |
if node[:ram] | |
cfg.vm.provider :virtualbox do |vb| | |
vb.customize ["modifyvm", :id, "--memory", node[:ram] ] | |
end | |
end | |
if node[:fwdports] | |
node[:fwdports].each do |tuple| | |
cfg.vm.network :forwarded_port, guest: tuple[:guest], host: tuple[:host] | |
end | |
end | |
cfg.vm.provision :shell, :inline => $overwrite_hosts_script | |
cfg.vm.provision :puppet do |puppet| | |
puppet.manifests_path = "manifests" | |
puppet.manifest_file = node[:hostname] + ".pp" | |
puppet.module_path = "modules" | |
# puppet.options = [ "--verbose" ] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment