forked from glennansley/Primary-Vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
237 lines (200 loc) · 10.1 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# Note: much of the documentation and code in this file is from Varying Vagrant Vagrants, the original base for this project
vagrant_dir = File.expand_path(File.dirname(__FILE__))
Vagrant.configure("2") do |root|
root.vm.define 'Primary Vagrant' do |config|
# Store the current version of Vagrant for use in conditionals when dealing
# with possible backward compatible issues.
vagrant_version = Vagrant::VERSION.sub(/^v/, '')
# Default Ubuntu Box
#
# This box is provided directly by Bento and is updated regularly.
config.vm.box = "bento/ubuntu-16.04"
config.vm.hostname = "pv"
# Default Box IP Address
#
# This is the IP address that your host will communicate to the guest through. In the
# case of the default `192.168.56.101` that we've provided, Virtualbox will setup another
# network adapter on your host machine with the IP `192.168.13.1` as a gateway.
#
# If you are already on a network using the 192.168.13.x subnet, this should be changed.
# If you are running more than one VM through Virtualbox, different subnets should be used
# for those as well. This includes other Vagrant boxes.
machineIP = '192.168.13.101'
config.vm.network :private_network, id: "pv_primary", ip: machineIP
# Local Machine Hosts
#
# If the Vagrant plugin Ghost (https://github.com/10up/vagrant-ghost) is
# installed, the following will automatically configure your local machine's hosts file to
# be aware of the domains specified below. Watch the provisioning script as you may need to
# enter a password for Vagrant to access your hosts file.
#
# By default, we'll include the domains set up by Primary Vagrant through the pv-hosts file
# located in the default-sites/ directory.
#
# Other domains can be automatically added by including a pv-hosts file containing
# individual domains separated by whitespace in subdirectories of user-data/ and user-date/sites/.
unless Vagrant.has_plugin?("landrush")
if defined?(VagrantPlugins::Ghost)
# Recursively fetch the paths to all pv-hosts files under the default-sites/, user-data/ and user-data/sites/ directories.
paths = Dir[File.join(vagrant_dir, 'default-sites', 'pv-hosts')] + Dir[File.join(vagrant_dir, 'user-data', 'pv-hosts')]+ Dir[File.join(vagrant_dir, 'user-data', 'sites', '**', 'pv-hosts')]
# Parse the found pv-hosts files for host names.
hosts = paths.map do |path|
# Read line from file and remove line breaks
lines = File.readlines(path).map(&:chomp)
# Filter out comments starting with "#"
lines.grep(/\A[^#]/)
end.flatten.uniq # Remove duplicate entries
# Pass the found host names to the ghost plugin so it can perform magic.
config.ghost.hosts = hosts
end
end
# If We have Landrush use it to set the toplevel to pv.
# The use of landrush will override all custom domains set and all sites and projects will simply revert to the "pv" toplevel.
if Vagrant.has_plugin?("landrush")
config.landrush.enabled = true
config.landrush.tld = 'pv'
end
# Forward Agent
#
# Enable agent forwarding on vagrant ssh commands. This allows you to use identities
# established on the host machine inside the guest. See the manual for ssh-add
config.ssh.forward_agent = true
# Configurations from 1.0.x can be placed in Vagrant 1.1.x specs like the following.
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--memory", 1024]
v.customize ["modifyvm", :id, "--name", "Primary Vagrant"]
v.customize ["modifyvm", :id, "--cpus", 1]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
# set auto_update to false, if you do NOT want to check the correct
# additions version when booting this machine
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = true
end
end
# Don't check for updates with every vagrant up
config.vm.box_check_update = false
# Drive mapping
#
# The following config.vm.share_folder settings will map directories in your Vagrant
# virtual machine to directories on your local machine. Once these are mapped, any
# changes made to the files in these directories will affect both the local and virtual
# machine versions. Think of it as two different ways to access the same file. When the
# virtual machine is destroyed with `vagrant destroy`, your files will remain in your local
# environment.
# Custom Mappings
#
# Use this to insert your own (and possibly rewrite) Vagrant config lines. Helpful
# for mapping additional drives. If a file 'pv-mappings' exists in the user-data/ folder or user-data/sites or any of its subfolders
# it will be evaluated as ruby inline as it loads.
if File.exists?(File.join(vagrant_dir,'user-data', 'pv-mappings')) then
eval(IO.read(File.join(vagrant_dir, 'user-data', 'pv-mappings')), binding)
end
Dir[File.join( vagrant_dir, 'user-data', 'sites', '**', 'pv-mappings')].each do |file|
eval(IO.read(file), binding)
end
eval(IO.read(File.join(vagrant_dir, 'default-sites', 'pv-mappings')), binding)
# Provisioning
#
# Process one or more provisioning scripts depending on the existence of custom files.
# Prevents stdin error for Ubuntu
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
# Make sure puppet is on the box
config.vm.provision "shell",
inline: "apt-get update -qy && apt-get install -qy software-properties-common puppet"
# Run the system setup on the first vagrant up.
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "provision"
puppet.manifest_file = "manifests"
puppet.module_path = "provision/modules"
puppet.facter = { "fqdn" => "pv" }
puppet.hiera_config_path = "provision/hiera.yaml"
end
# Run provisioning required every time we startup the box.
config.vm.provision "puppet", run: "always" do |puppet|
puppet.manifests_path = "user-data/"
puppet.manifest_file = "vhosts"
puppet.module_path = "provision/modules"
puppet.facter = { "fqdn" => "pv" }
puppet.hiera_config_path = "provision/hiera.yaml"
end
# Vagrant Triggers
#
# If the vagrant-triggers plugin is installed, we can run various scripts on Vagrant
# state changes like `vagrant up`, `vagrant halt`, `vagrant suspend`, and `vagrant destroy`
#
# These scripts are run on the host machine, so we use `vagrant ssh` to tunnel back
# into the VM and execute things. By default, each of these scripts calls db_backup
# to create backups of all current databases. This can be overridden with custom
# scripting. See the individual files in provision/lib/bin for details.
if defined? VagrantPlugins::Triggers
config.trigger.before :up do
system('./provision/lib/bin/vagrant_init.sh')
if File.exists?(File.join(vagrant_dir,'user-data', 'pv-init.sh')) then
system('./user-data/pv-init.sh')
end
Dir[File.join( 'user-data/sites', '**', 'pv-init.sh')].each do |file|
print file
system(file)
end
end
config.trigger.before :halt do
run_remote "bash /vagrant/provision/lib/bin/vagrant_halt.sh"
if File.exists?(File.join(vagrant_dir,'user-data', 'pv-halt.sh')) then
system('./user-data/pv-halt.sh')
end
Dir[File.join( 'user-data/sites', '**', 'pv-halt.sh')].each do |file|
print file
system(file)
end
end
config.trigger.before :suspend do
run_remote "bash /vagrant/provision/lib/bin/vagrant_suspend.sh"
if File.exists?(File.join(vagrant_dir,'user-data', 'pv-suspend.sh')) then
system('./user-data/pv-suspend.sh')
end
Dir[File.join( 'user-data/sites', '**', 'pv-suspend.sh')].each do |file|
print file
system(file)
end
end
config.trigger.before :destroy do
if File.exists?(File.join(vagrant_dir,'user-data', 'pv-destroy.sh')) then
system('./user-data/pv-destroy.sh')
end
Dir[File.join( 'user-data/sites', '**', 'pv-destroy.sh')].each do |file|
print file
system(file)
end
end
end
# Idea thanks to VVV.
puts "";
puts "\033[38;5;196m================================================"
puts "\033[38;5;33m _____ _"
puts "\033[38;5;33m| __ \\ (_)"
puts "\033[38;5;33m| |__) | __ _ _ __ ___ __ _ _ __ _ _"
puts "\033[38;5;33m| ___/ '__| | '_ ` _ \\ / _` | '__| | | |"
puts "\033[38;5;33m| | | | | | | | | | | (_| | | | |_| |"
puts "\033[38;5;33m|_| |_| |_|_| |_| |_|\\__,_|_| \\__, |"
puts "\033[38;5;33m __/ |"
puts "\033[38;5;33m |___/"
puts "\033[38;5;118m__ __ _"
puts "\033[38;5;118m\\ \\ / / | |"
puts "\033[38;5;118m \\ \\ / /_ _ __ _ _ __ __ _ _ __ | |_"
puts "\033[38;5;118m \\ \\/ / _` |/ _` | '__/ _` | '_ \\| __|"
puts "\033[38;5;118m \\ / (_| | (_| | | | (_| | | | | |_"
puts "\033[38;5;118m \\/ \\__,_|\\__, |_| \\__,_|_| |_|\\__|"
puts "\033[38;5;118m __/ |"
puts "\033[38;5;118m |___/"
puts "\033[38;5;196m================================================"
puts ""
puts " \033[38;5;80mPrimary Vagrant: \033[38;5;118m4.6.1"
puts ""
puts " \033[38;5;80mDocs: \033[38;5;220mhttps://github.com/ChrisWiegman/Primary-Vagrant/wiki"
puts ""
puts ""
puts "\033[0m"
config.vm.post_up_message="\033[38;5;118mPrimary Vagrant is ready. Happy developing!"
end
end