Created
December 18, 2014 15:57
-
-
Save Tombar/252d7722b852dc5d3abf to your computer and use it in GitHub Desktop.
Vagrantfile for puppet and puppetmaster
This file contains hidden or 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 : | |
puppetmaster = {:node_name => 'pm', :ip => '172.16.0.250', :memory => 1024, :cpus => 2} | |
nodes = { | |
'node10' => {:ip => '172.16.11.10'}, | |
'node11' => {:ip => '172.16.11.11'}, | |
'node12' => {:ip => '172.16.11.12', :memory => 1024, :cpus => 2}, | |
} | |
node_defaults = { | |
:domain => 'dev', | |
:memory => 384, | |
} | |
Vagrant.configure("2") do |config| | |
config.vm.box = "Debian-7.6.0-amd64-netboot" | |
config.vm.box_url = "http://repo.crvt.net/vagrant-boxes/linux/Debian-7.6.0-amd64-netboot.box" | |
if Vagrant.has_plugin?("vagrant-cachier") | |
# Configure cached packages to be shared between instances of the same base box. | |
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage | |
config.cache.scope = :box | |
end | |
if Vagrant.has_plugin?("vagrant-hostmanager") | |
# used to sync puppetmaster DNS to other nodes | |
config.hostmanager.enabled = true | |
config.hostmanager.include_offline = true | |
else | |
abort("Please run: vagrant plugin install vagrant-hostmanager") | |
end | |
# PuppetMaster config | |
if defined? puppetmaster | |
config.vm.define "pm" do |pm| | |
pm.vm.synced_folder '.', '/opt/puppet' | |
if Vagrant.has_plugin?("vagrant-r10k") | |
# https://github.com/jantman/vagrant-r10k | |
pm.r10k.puppet_dir = "." | |
pm.r10k.puppetfile_path = "Puppetfile" | |
pm.r10k.module_path = "modules" | |
else | |
# abort "[ERROR] you need vagrant-r10k plugin to work \nTry `vagrant plugin install vagrant-r10k" | |
pm.vm.provision :shell, :inline => "exec /usr/local/bin/run-r10k" | |
end | |
pm.vm.provision :shell, | |
:inline => "exec /usr/local/bin/run-puppet $@", | |
:args => "--verbose --summarize --environment development" | |
pm.vm.network(:private_network, :ip => puppetmaster[:ip]) | |
fqdn = "#{puppetmaster[:node_name]}.#{node_defaults[:domain]}" | |
pm.vm.hostname = fqdn | |
pm.vm.provider :virtualbox do |vb| | |
modifyvm_args = ['modifyvm', :id] | |
modifyvm_args << "--name" << fqdn | |
modifyvm_args << "--memory" << puppetmaster[:memory] | |
modifyvm_args << "--cpus" << puppetmaster[:cpus] | |
# Isolate guests from host networking. | |
modifyvm_args << "--natdnsproxy1" << "on" | |
modifyvm_args << "--natdnshostresolver1" << "on" | |
vb.customize(modifyvm_args) | |
end | |
end #end config.vm.define pm | |
end #end if defined? | |
nodes.each do |node_name, node_opts| | |
config.vm.define node_name do |node| | |
node_opts = node_defaults.merge(node_opts) | |
fqdn = "#{node_name}.#{node_opts[:domain]}" | |
node.vm.hostname = fqdn | |
if node_opts[:ip] | |
node.vm.network(:private_network, :ip => node_opts[:ip]) | |
end | |
node.vm.provider :virtualbox do |vb| | |
modifyvm_args = ['modifyvm', :id] | |
modifyvm_args << "--name" << fqdn | |
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 | |
#Setup all other nodes as puppet agents | |
config.vm.provision "puppet_server" do |puppet| | |
puppet.puppet_server = "#{puppetmaster[:node_name]}.#{node_defaults[:domain]}" | |
puppet.options = "--verbose --summarize --environment development" | |
puppet.facter = { "vagrant" => true } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment