-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
122 lines (99 loc) · 3.71 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
load 'repo/boxes.rb'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# vagrant-berkshelf hijacks cookbooks_path
#config.berkshelf.enabled = false
# vagrant multi-vm configuration
boxes.each do |opts|
# per node configuration
config.vm.define opts[:name] do |node|
node.ssh.forward_agent = true
#node.ssh.private_key_path = '~/.ssh/id_rsa'
# vagrant base boxes
images.each do |img|
if (img[:name] == opts[:os])
node.vm.box = img[:name]
node.vm.box_url = img[:url]
end
end
# VirtualBox provider
node.vm.provider "virtualbox" do |v|
if opts[:provider] == 'virtualbox'
v.memory = opts[:memory]
v.cpus = opts[:cpus]
# Private ip with second adapter only, else it won't work with centos
unless opts[:private_ip].nil?
node.vm.network "private_network", ip: opts[:private_ip], :adapter => 2
end
# port forwarding
unless opts[:ports].nil?
opts[:ports].each do |port|
node.vm.network "forwarded_port", guest: port[0], host: port[1]
end
end
end
end
# DigitalOcean provider
node.vm.provider "digital_ocean" do |v|
if opts[:provider] == 'digital_ocean'
node.vm.box = 'digital_ocean'
node.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box"
v.hostname = opts[:name]
v.token = opts[:token]
v.image = opts[:image]
v.region = opts[:region]
v.size = opts[:size]
end
end
# check if chef being used
unless opts[:chef].nil?
# Installs chef-client/chef-solo
config.omnibus.chef_version = :latest
# chef-solo configuration
node.vm.provision :chef_solo do |chef|
# custom chef-solo paths
chef.cookbooks_path = ["repo/cookbooks", "repo/site-cookbooks"]
chef.roles_path = "repo/roles"
chef.data_bags_path = "repo/data_bags"
opts[:chef].each do |role|
chef.add_role("#{role}")
end
# stop chef-solo from breaking the box
chef.json = {
"authorization" => {
"sudo" => {
"users" => [ "vagrant" ],
"passwordless" => true,
"sudoers_defaults" => ['!requiretty'],
}
}
}
end
end
# check if ansible being used
unless opts[:ansible].nil?
node.vm.provision "ansible" do |ansible|
opts[:ansible].each do |playbook|
ansible.playbook = "repo/#{playbook}"
end
end
end
# check if saltstack being used
unless opts[:salt].nil?
config.vm.synced_folder "repo/salt/", "/srv/salt/"
node.vm.provision "salt" do |salt|
salt.minion_config = "repo/minion"
salt.run_highstate = true
salt.colorize = true
salt.log_level = 'info'
salt.verbose = true
#opts[:salt].each do |minion|
#end
end
end
end
end
end