Skip to content

Instantly share code, notes, and snippets.

@amosshapira
Created December 9, 2014 10:14
Show Gist options
  • Save amosshapira/df9bc93b3b4ddc41dd24 to your computer and use it in GitHub Desktop.
Save amosshapira/df9bc93b3b4ddc41dd24 to your computer and use it in GitHub Desktop.
Vagrant file reading node dat afrom Hiera
boxes = Dir.glob("puppet/hiera/nodes/*.yaml").map {|f| YAML.load(File.read(f)) }
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
boxes.each do |attrs|
# Required attributes
boxname = attrs['box']
ip_address = attrs['ip_address']
fqdn = attrs['fqdn']
hostname = fqdn.split('.').first
# Optional attributes
gui = attrs['gui'] || false
guest = attrs['guest'] || 'linux'
config.vm.define(hostname) do |box|
box.vm.box = boxname
box.vm.network 'private_network', ip: ip_address
box.vm.hostname = fqdn
box.vm.provider 'virtualbox' do |v|
v.memory = 2048
v.cpus = 1
v.gui = gui
v.customize ['setextradata', :id, 'VBoxInternal/Devices/mc146818/0/Config/UseUTC', 1]
end
box.vm.provider 'vmware_fusion' do |v|
v.vmx['memsize'] = '2048'
v.vmx['numvcpus'] = '1'
v.gui = gui
end
# Invoke shell provisioner to prepare Puppet
if guest == 'windows'
box.vm.communicator = 'winrm'
box.vm.provision :shell do |s|
# From: https://github.com/hashicorp/puppet-bootstrap/blob/master/windows.ps1
s.path = 'install_puppet_windows.ps1'
s.args = "-PuppetVersion 3.4.3"
s.privileged = false
end
else
box.vm.provision :shell, :inline => install_puppet_debian #shell script to ensure correct puppet always available
end
box.vm.provision :puppet do |puppet|
puppet.manifests_path = 'puppet/manifests'
puppet.module_path = 'puppet/modules'
puppet.manifest_file = 'init.pp'
puppet.hiera_config_path = 'puppet/hiera.yaml'
puppet.working_directory = '/vagrant/puppet'
end
config.rspec.suppress_ci_stdout = false
config.rspec.dirs = ['spec/unit', 'spec/integration']
config.rspec.tests = ["#{hostname}/*_spec.rb"]
end
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
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment