Created
December 29, 2014 17:38
-
-
Save Tombar/3f9bcb7d0253f9c7cf2a to your computer and use it in GitHub Desktop.
Ultimate Puppet Vagrantfile
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 : | |
node_defaults = { | |
:domain => 'dev', | |
:memory => 384, | |
} | |
single = {:ip => '172.16.11.30', :memory => 1024, :cpus => 2} | |
multinodes = { | |
'db' => {:ip => '172.16.11.10'}, | |
'redis' => {:ip => '172.16.11.11'}, | |
'web' => {:ip => '172.16.11.12', :memory => 1024, :cpus => 2}, | |
} | |
###################### DO NOT TOUCH BELOW THIS LINE ######################### | |
nodes = {} | |
if ! ENV['provision'] || ENV['provision'].empty? | |
nodes['single'] = single | |
end | |
if ENV['provision'] == 'pm' | |
puppetmaster = {:node_name => 'pm', :ip => '172.16.0.250', :memory => 1024, :cpus => 2} | |
multinodes.each { |n, d| nodes[n] = d } | |
end | |
if ENV['provision'] == 'debug' | |
nodes[single] = single | |
multinodes.each { |n, d| nodes[n] = d } | |
end | |
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 | |
# PuppetMaster config | |
if ENV['provision'] == 'pm' | |
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 | |
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 "puppet" do |puppet| | |
puppet.manifests_path = '.' | |
puppet.manifest_file = "site.pp" | |
puppet.module_path = ['local_modules', 'modules'] | |
puppet.hiera_config_path = 'hiera.yaml' | |
puppet.options = "--verbose --summarize --environment development" | |
puppet.facter = { "vagrant" => true, "btng_box" => "vagrant", "btng_provision" => "pm" } | |
end | |
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 | |
if ENV['provision'] == 'pm' | |
#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, "btng_box" => "vagrant", "btng_provision" => "pm" } | |
end | |
else | |
config.vm.synced_folder '.', '/opt/puppet' | |
config.vm.provision "puppet" do |puppet| | |
puppet.manifests_path = '.' | |
puppet.manifest_file = "site.pp" | |
puppet.module_path = ['local_modules', 'modules'] | |
puppet.hiera_config_path = 'hiera.yaml' | |
puppet.options = "--verbose --summarize --environment development" | |
puppet.facter = { "vagrant" => true, "btng_box" => "vagrant", "btng_provision" => "pm" } | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment