-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
145 lines (110 loc) · 4.55 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
# vim: set filetype=ruby:
require 'yaml'
#require 'vagrant-hostmanager'
#require 'vagrant-vbguest' unless defined? VagrantVbguest::Config
require 'pp'
# Load configuration data from 'vagrant.yaml'
configuration_file = File.expand_path("vagrant.yaml", File.dirname(__FILE__))
configuration = YAML.load_file(configuration_file)
settings = configuration['vagrant']
puppetmaster = configuration['puppetmaster']
instances = configuration['instances']
# Create environment
Vagrant.configure("2") do |config|
def check_dependency(plugin_name)
unless Vagrant.has_plugin?(plugin_name)
puts "Vagrant [" + plugin_name + "] is required but is not installed\n" +
"please check if you have the plugin with the following command:\n" +
" $ vagrant plugin list\n" +
"If needed install the plugin:\n" +
" $ vagrant plugin install " + plugin_name + "\n"
abort "Missing [" + plugin_name + "] plugin\n\n"
end
end
# check_dependency 'vagrant-vbguest'
# check_dependency 'vagrant-hostmanager'
# configure image
config.vm.box = settings['box']
config.vm.box_check_update = settings['box_check_update']
config.ssh.insert_key = settings['ssh_insert_key']
# config.vbguest.auto_update = settings['auto_update']
# configure network
#config.vm.network "private_network", type: "dhcp"
if settings.has_key? 'public_network'
config.vm.network "public_network",
bridge: settings['public_network']['bridge'],
use_dhcp_assigned_default_route: settings['public_network']['use_dhcp_assigned_default_route']
end
# configure shared folder - for Development
config.vm.synced_folder ".", "/vagrant", disabled: true
if settings.has_key? 'hostmanager' and settings['hostmanager']
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
end # end hostmanager
unless puppetmaster.has_key? 'deactivated' or puppetmaster['deactivated']
config.vm.define puppetmaster['hostname'] do |guest|
if puppetmaster.has_key? 'box'
guest.vm.box = puppetmaster['box']
end # end box
if puppetmaster.has_key? 'box_url'
guest.vm.box_url = puppetmaster['box_url']
end # end box_url
if puppetmaster.has_key? 'private_ip'
guest.vm.network 'private_network', ip: puppetmaster['private_ip']
end # end private_ip
guest.vm.provider 'virtualbox' do |vb|
if puppetmaster.has_key? 'cpu_execution_cap'
vb.customize ["modifyvm", :id, "--cpuexecutioncap", puppetmaster['cpu_execution_cap'].to_s]
end
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
if puppetmaster.has_key? 'memory'
vb.memory = puppetmaster['memory']
end
if puppetmaster.has_key? 'cores'
vb.cpus = puppetmaster['cores']
end
end # end vb
if puppetmaster.has_key? 'mounts'
puppetmaster['mounts'].each do |mount|
guest.vm.synced_folder mount['host_path'], mount['guest_path'], owner: mount['owner'], group: mount['group']
end
end # end mounts
end # config.vm.define puppetmaster
end # if puppetmaster
instances.each do |instance|
next if instance.has_key? 'deactivated' and instance['deactivated']
config.vm.define instance['hostname'] do |guest|
if instance.has_key? 'box'
guest.vm.box = instance['box']
end
if instance.has_key? 'box_url'
guest.vm.box_url = instance['box_url']
end
if instance.has_key? 'private_ip'
guest.vm.network 'private_network', ip: instance['private_ip']
end
guest.vm.provider 'virtualbox' do |vb|
if instance.has_key? 'cpu_execution_cap'
vb.customize ["modifyvm", :id, "--cpuexecutioncap", instance['cpu_execution_cap'].to_s]
end
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
if instance.has_key? 'memory'
vb.memory = instance['memory']
end
if instance.has_key? 'cores'
vb.cpus = instance['cores']
end
end
if instance.has_key? 'mounts'
instance['mounts'].each do |mount|
guest.vm.synced_folder mount['host_path'], mount['guest_path'], owner: mount['owner'], group: mount['group']
end
end
end # config.vm.define instance
end # instances.each
end