forked from attachmentgenie/vagrant-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
163 lines (150 loc) · 6.06 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
159
160
161
162
163
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
vagrant_root = File.expand_path(File.dirname(__FILE__))
if File.file?(vagrant_root + '/vagrant.yaml')
vagrant_config = YAML.load_file(vagrant_root + '/vagrant.yaml')
elsif File.file?(vagrant_root + '/vagrant.yaml.dist')
vagrant_config = YAML.load_file(vagrant_root + '/vagrant.yaml.dist')
else
raise "No vagrant config is provided."
end
Vagrant.configure("2") do |config|
###############################################################################
# Plugin management #
###############################################################################
if vagrant_config['required_plugins']
plugins = vagrant_config['required_plugins']
else
plugins = ['vagrant-hostmanager', 'vagrant-puppet-install']
end
config.vagrant.plugins = plugins
###############################################################################
# Plugin settings #
###############################################################################
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :machine
end
if Vagrant.has_plugin?("vagrant-hostmanager")
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
end
###############################################################################
# Puppet settings #
###############################################################################
if vagrant_config['puppet_environment']
environment = vagrant_config['puppet_environment']
else
environment = 'production'
end
if Vagrant.has_plugin?("vagrant-puppet-install")
if vagrant_config['puppet_version']
version = vagrant_config['puppet_version']
else
version = :latest
end
config.puppet_install.puppet_version = version
end
###############################################################################
# VirtualBox settings #
###############################################################################
if vagrant_config['virtualbox_group']
config.vm.provider 'virtualbox' do |v|
v.customize [
'modifyvm', :id,
'--groups', vagrant_config['virtualbox_group']
]
end
end
###############################################################################
# VM definitions #
###############################################################################
config.vm.synced_folder ".", "/vagrant", disabled: true
if vagrant_config['nodes']
vagrant_config['nodes'].each do |node|
config.vm.define node["name"] do |srv|
srv.vm.box = node["box"]
if node["box_version"]
srv.vm.box_version = node["box_version"]
end
if node["box_check_update"]
srv.vm.box_check_update = node["box_check_update"]
end
srv.vm.hostname = node["hostname"]
if node["ports"]
node["ports"].each do |port|
srv.vm.network :forwarded_port, guest: port["guest"], host: port["host"]
end
end
srv.vm.provider "virtualbox" do |v|
if node["cpus"]
v.cpus = node["cpus"]
end
if node["memory"]
v.memory = node["memory"]
end
if node["disks"]
node["disks"].each_with_index do |disk, index|
medium_name = "disks/#{node["name"]}_#{disk["name"]}.vdi"
unless File.exist?(medium_name)
v.customize ['createmedium', '--filename', medium_name, '--variant', 'Fixed', '--size', disk["size"] * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', index +1 , '--device', 0, '--type', 'hdd', '--medium', medium_name]
end
end
end
srv.vm.network :private_network, ip: node["ip"]
if node["aliases"]
srv.hostmanager.aliases = node["aliases"]
end
if node["synced_folders"]
node["synced_folders"].each do |folder|
srv.vm.synced_folder folder["src"], folder["dst"]
end
end
case node["provision_type"]
when 'puppet_agent'
if node["puppetmaster"]
puppetmaster = node["puppetmaster"]
else
puppetmaster = "puppetmaster.#{environment}.vagrant"
end
srv.vm.provision "puppet_server" do |puppet|
puppet.options = "-t --environment #{environment}"
puppet.puppet_server = puppetmaster
end
srv.trigger.after :destroy do |trigger|
trigger.name = "Cleaning puppet certificate"
trigger.run = {inline: "vagrant ssh puppetmaster -c 'sudo /opt/puppetlabs/bin/puppetserver ca clean --certname #{node["hostname"]}'"}
end
else
if node["hiera_path"]
srv.vm.synced_folder node["hiera_path"], "/etc/puppetlabs/code/environments/#{environment}/data"
else
srv.vm.synced_folder "#{environment}/data", "/etc/puppetlabs/code/environments/#{environment}/data"
end
srv.vm.provision :puppet do |puppet|
puppet.environment = "#{environment}"
if node["environment_path"]
puppet.environment_path = node["environment_path"]
else
puppet.environment_path = "."
end
if node["hiera_config_path"]
puppet.hiera_config_path = node["hiera_config_path"]
else
puppet.hiera_config_path = "#{environment}/hiera.yaml"
end
end
end
if node["provision_shell"]
srv.vm.provision :shell, inline: node["provision_shell"]
end
end
end
else
raise "Node definitions are missing."
end
end