-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
executable file
·209 lines (170 loc) · 8 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# -*- mode: ruby -*-
# vi: set ft=ruby :
# |
# | Require YAML module
# |
require 'yaml'
# |
# | Get dir path
# |
dir = File.dirname(File.expand_path(__FILE__))
# |
# | Read YAML files
# |
servers = YAML.load_file("#{dir}/CONFIG.yaml")
# playbook_file = YAML.load_file("#{dir}/config.ansible.yml")
# |
# | Set values for message
# |
$mysql_user = servers['mysqlUser']
$mysql_pass = servers['mysqlPass']
$db_name = servers['dbName']
$db_user = servers['dbUser']
$db_pass = servers['dbPass']
$wpDomain = servers['wpDomain']
# | ············································································
# | Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
# | ············································································
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
servers["vms"].each do |server|
config.vm.define server["name"] do |srv|
# |
# | :::::: Box
# |
srv.vm.box = server["box"]
if server["box_version"]
srv.vm.box_version = server["box_version"]
end
if server["box_check_update"]
srv.vm.box_check_update = server["box_check_update"]
end
# |
# | :::::: Networdk
# |
if server["network"]["ip_private"]
srv.vm.network "private_network", ip: server["network"]["ip_private"]
end
if server["network"]["ip_public"] && server["network"]["bridge"]
srv.vm.network "public_network", ip: server["network"]["ip_public"], :bridge => server["network"]["bridge"]
end
# |
# | :::::: Ports forwarded
# |
if server["ports"]
server['ports'].each do |ports|
srv.vm.network "forwarded_port",
guest: ports["guest"],
host: ports["host"],
auto_correct: true
end
end
# |
# | :::::: Folder Sync
# |
if server["syncDir"]
server['syncDir'].each do |syncDir|
if syncDir["owner"] && syncDir["group"]
srv.vm.synced_folder syncDir["host"],
syncDir["guest"],
owner: "#{syncDir["owner"]}",
group: "#{syncDir["group"]}",
mount_options:["dmode=#{syncDir["dmode"]}",
"fmode=#{syncDir["fmode"]}"],
create: true
else
srv.vm.synced_folder syncDir['host'],
syncDir['guest'],
create: true
end
end
end
# | ············································································
# | :::::: Vm Setup
# | ············································································
srv.vm.provider :virtualbox do |vb|
vb.name = server["name"]
vb.memory = server["ram"]
if server["gui"]
vb.gui = server["gui"]
end
if server["cpus"]
vb.cpus = server["cpus"]
end
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
end
# | ············································································
# | :::::: Provisions
# | ············································································
# |
# | :::::: Provisions - Bash
# |
if server["bash"]
srv.vm.provision :shell, :path => server["bash"]
end
# |
# | :::::: Provisions - Puppet
# |
if server["puppet"]
srv.vm.provision :puppet do |puppet|
puppet.module_path = "puppet/modules"
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = server["puppet"]
end
end
# |
# | :::::: Provisions - Asible
# |
if server["ansible"]
srv.vm.provision:ansible do |ansible|
if server["ansible"]["verbose"]
ansible.verbose = server["ansible"]["verbose"]
end
if server["ansible"]["playbook"]
ansible.playbook = server["ansible"]["playbook"]
end
if server["ansible"]["inventory_path"]
ansible.inventory_path = server["ansible"]["inventory_path"]
end
if server["ansible"]["host_key_checking"]
ansible.host_key_checking = server["ansible"]["host_key_checking"]
end
if server["ansible"]["limit"]
ansible.limit = server["ansible"]["limit"]
end
end
File.open('ansible/inventory' ,'w') do |f|
f.write "[vagrant]\n"
f.write "#{server["network"]["ip_private"]}\n"
end
end
# | ············································································
# | :::::: Vagrant Message
# | ············································································
srv.vm.post_up_message = " \e[0;37m
················································································
WORDPRESS > Install
················································································
Url : \e[0;33mhttp://#{server['network']['ip_private']}\e[0;37m
Url (optional) : \e[0;33mhttp://#{$wpDomain}\e[0;37m
Database Name : \e[0;33m#{$db_name}\e[0;37m
Database User : \e[0;33m#{$db_user}\e[0;37m
Database Pass : \e[0;33m#{$db_pass}\e[0;37m
Mysql User : #{$mysql_user}
Mysql Pass : #{$mysql_pass}
················································································
Edit Hosts Files (optional)
················································································
In your terminal copy and run this command:
\e[0;33mecho \"\\n#{server['network']['ip_private']} #{$wpDomain}\" | sudo tee -a /etc/hosts\e[0;37m
················································································
VAGRANT VM
················································································
Vm Name : #{server['name']}
Private ip : \e[0;33m#{server["network"]["ip_private"]}\e[0;37m
················································································
\e[32m"
end
end
end