diff --git a/Vagrantfile b/Vagrantfile index 5b7d5c6..60319c0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,116 +1,117 @@ Vagrant.require_version ">= 1.6.5" # =========================== # VARIABLES + BOX DEFINITIONS # =========================== SSH_BASE_PORT = 2610 VARNISH_BASE_PORT = 6100 PUPPET_VERSION = "4.10.6" BOXES = [ { name: "debian7", box: "debian/wheezy64", version: "7.11.2" }, { name: "debian8", box: "debian/jessie64", version: "8.9.0" }, { name: "ubuntu14", box: "ubuntu/trusty64", version: "20170810.0.0" }, { name: "ubuntu16", box: "ubuntu/xenial64", version: "20170811.0.0" }, { name: "centos6", box: "centos/6", version: "1707.01" }, { name: "centos7", box: "centos/7", version: "1707.01" } ] MODULES = [ # Module dependencies { name: "puppetlabs-stdlib", version: "4.17.1" }, { name: "puppetlabs-apt", version: "2.4.0" }, { name: "stahnma-epel", version: "1.2.2" }, { name: "puppet-selinux", version: "0.8.0" }, # Test dependencies { name: "puppetlabs-concat", version: "2.2.1" }, { name: "puppet-nginx", version: "0.6.0" } ] # ============== # VAGRANT CONFIG # ============== unless Vagrant.has_plugin?("vagrant-puppet-install") raise 'vagrant-puppet-install is not installed!' end Vagrant.configure("2") do |config| local_username ||= `whoami`.strip config.puppet_install.puppet_version = PUPPET_VERSION # Handle Puppet 3 and 4/5 paths if PUPPET_VERSION.start_with?('3') puppet_bin_path = '/usr/bin/puppet' module_path = '/etc/puppet/modules' else puppet_bin_path = '/opt/puppetlabs/bin/puppet' module_path = '/etc/puppetlabs/code/environments/production/modules' end # = Actually do some work BOXES.each_with_index do |definition,idx| name = definition[:name] ip = 254 - idx config.vm.define name, autostart: false do |c| # == Basic box setup c.vm.box = definition[:box] c.vm.box_version = definition[:version] unless definition[:version].nil? c.vm.hostname = "#{local_username}-varnish-vagrant-#{name}" c.vm.network :private_network, ip: "10.0.254.#{ip}" # == Shared folder if Vagrant::Util::Platform.darwin? config.vm.synced_folder ".", "/vagrant", nfs: true c.nfs.map_uid = Process.uid c.nfs.map_gid = Process.gid else c.vm.synced_folder ".", "/vagrant", type: "nfs" end # == Disable vagrant's default SSH port, then configure our override new_ssh_port = SSH_BASE_PORT + idx c.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: "true" c.ssh.port = new_ssh_port c.vm.network :forwarded_port, guest: 22, host: new_ssh_port # == Add forwarded port for Varnish (8080) new_varnish_port = VARNISH_BASE_PORT + idx c.vm.network :forwarded_port, guest: 6081, host: new_varnish_port # == Set resources if configured c.vm.provider "virtualbox" do |v| v.name = "puppet_varnish_#{name}" v.memory = definition[:memory] unless definition[:memory].nil? v.cpus = definition[:cpus] unless definition[:cpus].nil? end # == Install git ... with Puppet! c.vm.provision :shell, :inline => "#{puppet_bin_path} resource package git ensure=present" # == Install modules MODULES.each do |mod| if mod[:git].nil? if mod[:version].nil? mod_version = '' else mod_version = " --version #{mod[:version]}" end c.vm.provision :shell, :inline => "#{puppet_bin_path} module install #{mod[:name]}#{mod_version}" else mod_name = mod[:name].split('-').last c.vm.provision :shell, :inline => "if [ ! -d #{module_path}/#{mod_name} ]; then git clone #{mod[:git]} #{module_path}/#{mod_name}; fi" end end c.vm.provision :shell, :inline => "if [ ! -L #{module_path}/varnish ]; then ln -s /vagrant #{module_path}/varnish; fi" # == Finally, run Puppet! - c.vm.provision :shell, :inline => "STDLIB_LOG_DEPRECATIONS=false #{puppet_bin_path} apply --verbose --show_diff /vagrant/tests/init.pp" + c.vm.provision :shell, :inline => "STDLIB_LOG_DEPRECATIONS=false #{puppet_bin_path} apply --verbose --show_diff /vagrant/examples/init.pp" + c.vm.provision :shell, :inline => "echo 'Varnish test at http://127.0.0.1:#{new_varnish_port}'" end end end diff --git a/tests/init.pp b/examples/init.pp similarity index 80% rename from tests/init.pp rename to examples/init.pp index 01f74aa..d53ba18 100644 --- a/tests/init.pp +++ b/examples/init.pp @@ -1,70 +1,71 @@ node default { $version = '4.1' # == Package Versions case $::osfamily { 'Debian': { if $::operatingsystem == 'Debian' and versioncmp($::lsbdistrelease,'8.0') >= 0 and $version == '3.0' { $package_ensure = '3.0.7-1~jessie' } elsif $::operatingsystem == 'Ubuntu' and versioncmp($::lsbdistrelease,'16.04') >= 0 and $version == '4.0' { $package_ensure = '4.0.5-1~xenial' } else { $package_ensure = 'present' } } 'RedHat': { if $::operatingsystemmajrelease == '7' and $version == '4.0' { $package_ensure = '4.0.4-1.el7' } else { $package_ensure = 'present' } } default: { $package_ensure = 'present' } } # == Varnish class { '::varnish': - varnish_version => $version, - package_ensure => $package_ensure, - listen => ['127.0.0.1:8890',"${::ipaddress}:8888"], - storage_type => 'malloc', - storage_size => '64M', - instance_name => "vagrant-varnish${version}", + varnish_version => $version, + package_ensure => $package_ensure, + listen => ['127.0.0.1:8888',"${::ipaddress}:6081"], + storage_additional => ['file,/var/lib/varnish/varnish_additional.bin,1G'], + storage_type => 'malloc', + storage_size => '64M', + instance_name => "vagrant-varnish${version}", } # == Nginx + test file class { '::nginx': server_purge => true, confd_purge => true, } if $::osfamily == 'Debian' { $nginx_port = 8080 } else { $nginx_port = 80 } ::nginx::resource::server { 'default': listen_port => $nginx_port, listen_ip => '127.0.0.1', www_root => '/usr/share/nginx/html', } file { '/usr/share/nginx/html/index.html': ensure => file, owner => 'root', group => 'root', mode => '0644', content => "VarnishHello, I am Varnish ${version} running on ${::hostname}\n", require => Package['nginx'], } }