Skip to content

Instantly share code, notes, and snippets.

@dubcl
Created July 31, 2017 22:15
Show Gist options
  • Save dubcl/d663ef913115767790f8b52e179f8805 to your computer and use it in GitHub Desktop.
Save dubcl/d663ef913115767790f8b52e179f8805 to your computer and use it in GitHub Desktop.
# -*- mode: ruby -*-
# vi: set ft=ruby :
## == required plugins and params == ##
# vagrant plugin install vagrant-hosts
# vagrant plugin install vagrant-cachier
# gem install ruby-libvirt
# gem install fog
# vagrant plugin install vagrant-libvirt
# export VAGRANT_DEFAULT_PROVIDER="libvirt"
##
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "foo-box"
# check http://www.vagrantbox.es and change the follow url
config.vm.box_url = "http://example.com/foo.box"
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.auto_detect = true
end
config.vm.provider :libvirt do |kvm|
kvm.driver = 'kvm'
kvm.memory = 1024
kvm.cpus = 2
kvm.cpu_mode = 'host-passthrough'
end
# config for individual vm for puppet master
config.vm.define "puppet" do |master|
master.vm.hostname = "puppet-master.foo.com"
master.vm.network :private_network, ip: "172.16.210.10"
master.vm.provision :hosts do |provisioner|
provisioner.autoconfigure = true
provisioner.add_host '127.0.0.1', ['puppet-master.foo.com', 'puppet-master', 'puppet']
end
master.vm.provision :shell, :inline => "echo -e 'deb http://mirrors.tecnoera.com/debian wheezy main non-free contrib\ndeb-src http://mirrors.tecnoera.com/debian wheezy main non-free contrib\n\ndeb http://ftp.br.debian.org/debian-security/ wheezy/updates main contrib non-free\ndeb-src http://ftp.br.debian.org/debian-security/ wheezy/updates main contrib non-free' > /etc/apt/sources.list"
master.vm.provision :shell, :inline => "apt-get update && apt-get -y dist-upgrade"
master.vm.provision :shell, :path => "master_conf/puppet_master.sh"
master.vm.provision :shell, :path => "master_conf/puppet_r10k.sh"
master.vm.provision :puppet do |puppet|
puppet.manifests_path = "master_conf/manifests"
puppet.manifest_file = "default.pp"
puppet.options = "--verbose --debug --modulepath /home/vagrant/modules"
end
master.vm.synced_folder "puppet/manifests", "/etc/puppet/manifests", type: '9p'
master.vm.synced_folder "puppet/modules", "/etc/puppet/modules", type: '9p'
master.vm.synced_folder "puppet/hieradata", "/etc/puppet/hieradata", type: '9p'
master.vm.provider :libvirt do |kvm|
kvm.memory = 2048
end
end
#Custom nodes
nodes = {
:test1 => {:host => 'test1', :domain => 'foo.com', :ip => '172.16.210.44', :mem => 1024 },
}
nodes.each do |name, options|
config.vm.define name do |node|
node.vm.provision :hosts do |provisioner|
provisioner.autoconfigure = true
provisioner.add_host '172.16.210.10', ['puppet-master.foo.com', 'puppet-master', 'puppet']
end
node.vm.provision :shell, :inline => "echo -e 'deb http://ftp.cl.debian.org/debian wheezy main non-free contrib\ndeb-src http://ftp.cl.debian.org/debian wheezy main non-free contrib\n\ndeb http://ftp.cl.debian.org/debian-security/ wheezy/updates main contrib non-free\ndeb-src http://ftp.cl.debian.org/debian-security/ wheezy/updates main contrib non-free' > /etc/apt/sources.list"
node.vm.provision :shell, :inline => "apt-get update && apt-get -y dist-upgrade"
node.vm.provision :shell, :inline => "sed -i '/templatedir/d' /etc/puppet/puppet.conf"
node.vm.provision :shell, :inline => "sed -i 's/START=no/START=yes/g' /etc/default/puppet"
node.vm.provision "puppet_server" do |puppet|
puppet.puppet_server = "puppet-master.foo.com"
puppet.options = "--verbose --debug"
end
node.vm.hostname = "#{options[:host]}.#{options[:domain]}"
node.vm.network :private_network, ip: options[:ip]
node.vm.provider :libvirt do |kvm|
kvm.memory = options[:mem] if options[:mem]
kvm.cpus = options[:cpu] if options[:cpu]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment