forked from tag1consulting/puppet-centos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
158 lines (135 loc) · 5.53 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# -*- mode: ruby -*-
# vi: set ft=ruby :
# You can override or add to this file by configuring the Vagrantfile.local
# Note the provided Vagrantfile.local.example
VAGRANTFILE_API_VERSION = "2"
# Require 1.6.2 since that's when the rsync synced folder was stabilized.
Vagrant.require_version ">= 1.6.2"
# Load zlib so port forwarding works.
require 'zlib'
project = File.basename(File.dirname(__FILE__));
dirname = File.dirname(__FILE__)
localfile = dirname + "/Vagrantfile.local"
default = dirname + "/scripts/Vagrantfile.default"
if File.exist?(localfile)
load localfile
elsif File.exists?(default)
load default
end
# Optional goodies like colorized output
extras = dirname + "/scripts/Vagrantfile.extras"
if File.exist?(extras)
load extras
end
# Configure the domain
if !defined? $domainname
$domainname = "tag1consulting.com"
end
Vagrant.configure('2') do |config|
if defined? $box
config.vm.box = $box
else
config.vm.box = "tag1/centos7-50GB-vbguest"
end
if defined? $box_url
config.vm.box_url = $box_url
else
config.vm.box_url = "http://pkg.tag1consulting.com/vagrant-boxes/centos7-50GB-vbguest/metadata.json"
end
# Enable ssh agent forwarding
config.ssh.forward_agent = true
# You can define a $vms array in Vagrantfile.local which says what vms should be launched.
if !defined? $vms
$vms = {
"default" => { "fqdn" => "vagrant-test.tag1consulting.com", "ipaddress" => "10.10.10.10", "memory" => "2048", "cpus" => "2" },
}
end
$vms.each do |name, attributes|
config.vm.define "#{name}" do |name|
# myvm.vm.provision "shell", inline: "echo hello from slave #{myname}"
name.vm.network :private_network, ip: attributes["ipaddress"]
name.vm.hostname = attributes['fqdn']
$forwarded_port = attributes["forwarded_port"]
unless $forwarded_port.nil? || $forwarded_port == 0
# Generate unique port forward based on fqdn and directory
portname = dirname + '/' + name.vm.hostname
crc = Zlib::crc32(portname)
$port_base = (crc % 500) * 100 + 3000
if !defined? $port_base
$port_base = 4000
end
$port = $port_base + $forwarded_port
name.vm.network :forwarded_port, guest: $forwarded_port, host: $port, auto_correct: true
end
name.vm.hostname = attributes['fqdn']
config.vm.provider "virtualbox" do |v|
v.memory = attributes['memory']
v.cpus = attributes['cpus']
# Enable APIC, which is required for multiple CPU support under Virtualbox.
v.customize ["modifyvm", :id, "--ioapic", "on"]
end
end
end
# Optional share for yum packages so that they don't have be downloaded all the time
# when doing a clean build of different VMs.
# To turn this on, set vagrant_yum_cache in your Vagrantfile.local,
# $vagrant_yum_cache = "/var/cache/vagrantyum_cache"
if defined? $vagrant_yum_cache
config.vm.synced_folder $vagrant_yum_cache, "/var/cache/yum"
config.vm.provision "shell",
inline: "echo '--- Turning on yum caching in /etc/yum.conf ---'; perl -pi.bak -e 's/keepcache=0/keepcache=1/' /etc/yum.conf"
end
# Mount any development directories
if defined? $dev_mounts
# Default mount settings.
$dev_mounts.each do |mount, attributes|
# Handle mount options for various mount types.
# Mounts can be defined in Vagrantfile.local.
if attributes['type']=="virtualbox"
config.vm.synced_folder attributes['host_mountpoint'], attributes['vm_mountpoint'], type: attributes['type'], owner: attributes['owner'], group: attributes['group'], mount_options: attributes['mount_options']
elsif attributes['type']=="rsync"
config.vm.synced_folder attributes['host_mountpoint'], attributes['vm_mountpoint'], type: attributes['type'], owner: attributes['owner'], group: attributes['group'], rsync__exclude: attributes['rsync__exclude'], rsync__chown: attributes['rsync__chown'], rsync__auto: attributes['rsync__auto']
elsif attributes['type'] == 'nfs'
config.vm.synced_folder attributes['host_mountpoint'], attributes['vm_mountpoint'], type: attributes['type']
end
end
end
# Install r10k using the shell provisioner and download the Puppet modules
config.vm.provision "shell", path: 'bootstrap.sh'
# Puppet provisioner for primary configuration
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "manifests"
puppet.module_path = [ "modules", "site", "dist" ]
puppet.manifest_file = "site.pp"
puppet.hiera_config_path = "hiera.yaml"
puppet.working_directory = "/vagrant"
puppet.options = ""
# In vagrant environment it can be hard for facter to get this stuff right
puppet.facter = {
"dev_environment" => "vagrant",
"domain" => $domainname,
}
end
# Run post-puppet.sh
config.vm.provision "shell", path: 'scripts/post-puppet.sh'
if Vagrant.has_plugin?("vagrant-triggers")
config.trigger.after [:up, :resume, :status, :restart, :reload] do
$banner = "Build complete".green + " for ".clean + (project).to_s.bold.yellow
$link = "http://localhost:" + $port.to_s + "/"
puts
info $banner
unless $forwarded_port.nil? || $forwarded_port == 0
$link = "http://localhost:" + $port.to_s + "/"
info $link.underline
end
puts
end
end
end
# Determine if we are on windows
# http://happykoalas.com/blog/2012/04/vagrant-and-using-nfs-only-on-non-windows-host/
def Kernel.is_windows?
# Detect if we are running on Windows
processor, platform, *rest = RUBY_PLATFORM.split("-")
platform == 'mingw32'
end