forked from fsalum/puppet-newrelic
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Vagrantfile
121 lines (101 loc) · 4.26 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Vagrant.require_version ">= 1.6.5"
# ===========================
# VARIABLES + BOX DEFINITIONS
# ===========================
WEB_BASE_PORT = 6800
SSH_BASE_PORT = 2600
PUPPET_VERSION = "4.10.9"
DEFAULT_TEST = "mod_php"
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: "puppet-download_file", version: "1.2.1" },
{ name: "puppetlabs-stdlib" },
{ name: "puppetlabs-apt", version: "4.1.0" },
# Test dependencies
{ name: "Slashbunny-phpfpm", version: "0.0.13" },
{ name: "puppet-nginx", git: "https://github.com/voxpupuli/puppet-nginx.git" },
{ name: "puppetlabs-concat", version: "4.0.1" },
{ name: "puppetlabs-apache", version: "2.0.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
# = Actually do some work
BOXES.each_with_index do |definition,idx|
name = definition[:name]
ip = 254 - idx
config.puppet_install.puppet_version = PUPPET_VERSION
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}-newrelic-vagrant-#{name}"
c.vm.network :private_network, ip: "10.0.255.#{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
# == Set resources if configured
c.vm.provider "virtualbox" do |v|
v.name = "puppet_newrelic_#{name}"
v.memory = definition[:memory] unless definition[:memory].nil?
v.cpus = definition[:cpus] unless definition[:cpus].nil?
end
# == Setup port forwarding for port 80, and extras if configured
web_port = WEB_BASE_PORT + idx
c.vm.network :forwarded_port, guest: 80, host: web_port
if not definition[:ports].nil?
definition[:ports].each do |port_info|
c.vm.network :forwarded_port, port_info
end
end
# == Allow passing a test file
if ENV['TEST_FILE'].nil?
test_file = DEFAULT_TEST
else
test_file = ENV['TEST_FILE']
end
# == Install git ... with Puppet!
c.vm.provision :shell, :inline => "/opt/puppetlabs/bin/puppet 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 => "/opt/puppetlabs/bin/puppet module install #{mod[:name]}#{mod_version}"
else
mod_name = mod[:name].split('-').last
c.vm.provision :shell, :inline => "if [ ! -d /etc/puppetlabs/code/environments/production/modules/#{mod_name} ]; then git clone #{mod[:git]} /etc/puppetlabs/code/environments/production/modules/#{mod_name}; fi"
end
end
c.vm.provision :shell, :inline => "if [ ! -L /etc/puppetlabs/code/environments/production/modules/newrelic ]; then ln -s /vagrant /etc/puppetlabs/code/environments/production/modules/newrelic; fi"
# == Finally, run Puppet!
c.vm.provision :shell, :inline => "STDLIB_LOG_DEPRECATIONS=false /opt/puppetlabs/puppet/bin/puppet apply --verbose --show_diff /vagrant/examples/#{test_file}.pp"
end
end
end