-
Notifications
You must be signed in to change notification settings - Fork 2
/
Vagrantfile
135 lines (114 loc) · 5.37 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
settings = YAML::load(File.read("devbox_config.yaml"))
aliases = "aliases"
supported_os = ["ubuntu"]
supported_ubuntu_versions = ["14.04", "16.04", "18.04"]
default_os = "ubuntu"
default_os_version = "16.04"
Vagrant.configure("2") do |config|
if settings.has_key?("servers")
groups = Hash.new {|h,k| h[k]=[]}
port_count = 0
settings["servers"].each_with_index do |server, server_count|
name = "#{server["name"] ||= "devbox"}"
hostname = "#{server["hostname"] ||= "devbox"}"
if settings["servers"].size > 1
machine_name = "#{name}_vm#{server_count}"
machine_hostname = "#{hostname}-vm#{server_count}"
else
machine_name = name
machine_hostname = hostname
end
groups[server["group"] ||= "all"] << machine_name
if server.has_key?("os")
os = server["os"]
unless supported_os.include?("#{os}")
abort("OS #{os} not recognised. Only #{supported_os} are currenly supported with DevBox.")
end
end
if server.has_key?("os_version")
supported_os_version = "supported_#{os}_versions"
os_version = server["os_version"]
unless supported_ubuntu_versions.include?("#{os_version}")
abort("#{os} version #{os_version} not recognised. Only #{supported_os_version} are currenly supported with DevBox.")
end
end
config.vm.define machine_name do |machine|
# Configure the vagrant box.
machine.vm.hostname = machine_hostname
machine.vm.box = server["box"] ||= "bento/#{os ||= default_os}-#{os_version ||= default_os_version}"
machine.vm.box_version = server["box_version"] ||= ">= 0"
# Configure VirtualBox settings.
machine.vm.provider "virtualbox" do |vb|
vb.name = machine_name
vb.memory = server["memory"] ||= "1024"
vb.cpus = server["cpus"] ||= "1"
# vb.linked_clone = true
if server.has_key?("gui") && server["gui"] == true
vb.gui = true
end
end
# Configure private network.
if server.has_key?("ip")
machine.vm.network "private_network", ip: server["ip"]
else
machine.vm.network "private_network", type: "dhcp"
end
# Configure public/bridged network.
if server.has_key?("public_ip")
machine.vm.network "public_network", ip: server["public_ip"], bridge: server["bridge"] ||= "en1: Wi-Fi (AirPort)"
end
# Configure ports to forward.
if server.has_key?("forward_ports")
server["forward_ports"].each do |port|
machine.vm.network "forwarded_port", guest: port["guest"], host: port["host"] + port_count, auto_correct: true
end
port_count += 1
end
# Disable default shared folder.
machine.vm.synced_folder ".", "/vagrant", disabled: true
# Configure shared folders.
if server.has_key?("folders")
server["folders"].each do |folder|
if folder["type"] == "nfs"
machine.vm.synced_folder folder["map"], folder["to"],
create: folder["create"] ||= false,
owner: folder["owner"] ||= "",
group: folder["group"] ||= "",
type: "nfs",
mount_options: [
"dmode=#{folder['dmode'] ||= 755}",
"fmode=#{folder['fmode'] ||= 644}",
"actimeo=1",
"nolock"
]
else
machine.vm.synced_folder folder["map"], folder["to"],
create: folder["create"] ||= false,
owner: folder["owner"] ||= "",
group: folder["group"] ||= "",
mount_options: [
"dmode=#{folder['dmode'] ||= 755}",
"fmode=#{folder['fmode'] ||= 644}"
]
end
end
end
# Provision the servers.
machine.vm.provision "ansible" do |ansible|
if settings.has_key?("galaxy_role_file")
ansible.galaxy_role_file = settings["galaxy_role_file"]
ansible.galaxy_roles_path = settings["galaxy_roles_path"] ||= "roles"
end
ansible.playbook = "configure.yml"
ansible.groups = groups
if settings.has_key?("debug") and settings["debug"]
ansible.verbose = '-vvvv'
end
end
end
end
end
end