This repository has been archived by the owner on Jun 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathVagrantfile
278 lines (230 loc) · 9.83 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# -*- mode: ruby -*-
# vi: set ft=ruby :
# NETWORKING
# Set the hostname of the VM. This will almost always need to be changed to
# match your project. This should be fully-qualified, ending in a TLD like
# .local or .lan.
HOSTNAME = "trusty-lamp.local"
# Set this to true to add a public IP for this machine. The IP will be served
# by whatever network gives your host an IP address. This is useful for testing
# with mobile devices.
#
# This is disabled by default as it can break on some captive Wifi networks
# like those in airprots or hotels. Turn this back off if your VM doesn't boot
# in a new network environment!
PUBLIC_NETWORK = false
# Set a static IP for this box in addition to the DHCP IP.
# STATIC_IP = "192.168.100.100"
# FILE SYNCING
# Choose between "vbox", "nfs", "rsync", or "none" sync types.
# - vbox is the simplest, but also the slowest.
# - NFS doesn't work on Windows, but is decently fast.
# - rsync is the fastest, but doesn't automatically run. It also has some
# performance issues in Vagrant 1.6. See
# https://github.com/smerrill/vagrant-gatling-rsync for a temporary
# solution.
SYNC_TYPE = "vbox"
# By default, sync a "www" directory within this project. This can be changed
# to an absolute path. By default, Apache is configured to look for a docroot
# directory within this directory to serve from.
SYNC_DIRECTORY = "www"
# RESOURCES
# The architecture (32 or 64 bit) of the virtual machine. This changes the
# base box that is used. If you want to change the arch on an existing machine,
# you should destroy the machine first.
ARCH = 32
# The number of CPU cores to expose to the virtual machine.
CPUS = 1
# The maximum amount of memory in MB to expose to the virtual machine. MySQL is
# configured to use ~384MB of memory for caches, so if this is reduced be sure
# to update /etc/mysql/conf.d/local.cnf and possibly Apache's MaxClients as
# well.
MEMORY = 1024
# Vagrant now generates a unique SSH key and installs it into a VM when it is
# first booted. This complicates SSH'ing to machines on other hosts, since you
# have to manually copy over the SSH key.
#
# Set this to true to use the old-style "insecure" SSH key. If you do this,
# know that anyone on the local network can SSH in to your VM.
USE_INSECURE_KEY = false
# Provision this VM on boot using Puppet. This is used when updating the base
# boxes, and isn't required for day-to-day use. When turning on, a box will
# need to be rebooted so Vagrant can mount the proper directories.
PROVISION = false
# 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|
# PRIVATE NETWORK
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", type: "dhcp"
# Use this instead to hard code a specific IP address.
if defined? STATIC_IP
config.vm.network "private_network", ip: STATIC_IP
end
# Use this to allow access to the VM from outside of your host machine. This
# is useful for testing with phones or tablets. However, it often does not
# work on public Wifi networks, so it's disabled by default.
if PUBLIC_NETWORK
config.vm.network "public_network"
end
# HOSTNAME
# Set the hostname.
config.vm.hostname = HOSTNAME
# FILE SYNCING
# Create our sync directory if needed.
vagrant_directory = File.dirname(__FILE__)
if SYNC_DIRECTORY[0,1] != "/" || SYNC_DIRECTORY[1,3] != ":\\"
share_directory = vagrant_directory + "/" + SYNC_DIRECTORY
end
if SYNC_TYPE != "none" && !Dir.exists?(share_directory)
Dir.mkdir(share_directory)
Dir.mkdir(share_directory + "/docroot")
index = "<?php phpinfo();\n"
File.open(share_directory + "/docroot/index.php", 'w') { |f| f.write(index) }
end
case SYNC_TYPE
when "vbox"
config.vm.synced_folder SYNC_DIRECTORY, "/var/www", owner: "www-data", group: "www-data"
when "nfs"
config.vm.synced_folder SYNC_DIRECTORY, "/var/www", type: "nfs"
when "rsync"
config.vm.synced_folder SYNC_DIRECTORY, "/var/www", type: "rsync", rsync__exclude: ".git/", group: "www-data", rsync__args: ["--verbose", "--archive", "--delete", "-z", "--chmod=g+rwX"]
end
#
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# Don't boot with headless mode
# vb.gui = true
# Use linked clones in Virtualbox. This is currently opt-in and not
# supported in vanilla VMWare Fusion, so we only set this for VirtualBox.
vb.linked_clone = true
# RESOURCE SETTINGS
vb.customize ["modifyvm", :id, "--memory", MEMORY]
## ioapic is required for > 1 CPU core.
if CPUS > 1
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
vb.customize ["modifyvm", :id, "--cpus", CPUS]
# This fixes DNS lag issues with Virtualbox.
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
# VirtualBox 5 supports paravirtualization, and defaults this setting to
# 'legacy' which isn't enabling KVM.
begin
if VagrantPlugins::ProviderVirtualBox::Driver::Meta.new.version >= "5.0.0"
vb.customize ['modifyvm', :id, '--paravirtprovider', 'default']
end
rescue Vagrant::Errors::VirtualBoxNotDetected
end
end
config.vm.provider "vmware_desktop" do |v|
v.vmx["memsize"] = MEMORY
v.vmx["numvcpus"] = CPUS
v.vmx["tools.synctime"] = true
end
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
if ARCH == 32
config.vm.box = "deviantintegral/trusty32-lamp"
elsif ARCH == 64
config.vm.box = "deviantintegral/trusty64-lamp"
end
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
# config.vm.box_url = "http://domain.com/path/to/above.box"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
# config.ssh.forward_agent = true
# Replace the SSH key of VMs on boot.
config.ssh.insert_key = !USE_INSECURE_KEY
# Vagrant sets the hostname after the VM has run services. Restart Avahi to
# ensure that it is broadcasting an updated hostname.
config.vm.provision "shell",
inline: "service avahi-daemon restart",
run: "always"
# Fix eth1 routing that vagrant adds. It just slows down boot time (A LOT!)
config.vm.provision "shell",
inline: "sed -i '/post-up route del default dev/d' /etc/network/interfaces",
run: "always"
#
# View the documentation for the provider you're using for more
# information on available options.
# Enable provisioning with Puppet stand alone. Puppet manifests
# are contained in a directory path relative to this Vagrantfile.
# You will need to create the manifests directory and a manifest in
# the file base.pp in the manifests_path directory.
#
# An example Puppet manifest to provision the message of the day:
#
# # group { "puppet":
# # ensure => "present",
# # }
# #
# # File { owner => 0, group => 0, mode => 0644 }
# #
# # file { '/etc/motd':
# # content => "Welcome to your Vagrant-built virtual machine!
# # Managed by Puppet.\n"
# # }
#
if PROVISION == true
config.vm.provision "puppet", run: "always" do |puppet|
puppet.manifests_path = "manifests"
puppet.module_path = "modules"
puppet.manifest_file = "site.pp"
puppet.options = "--hiera_config /vagrant/hiera.yaml"
end
config.vm.provision "shell",
path: "cleanup.sh",
run: "always"
end
# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding
# some recipes and/or roles.
#
# config.vm.provision "chef_solo" do |chef|
# chef.cookbooks_path = "../my-recipes/cookbooks"
# chef.roles_path = "../my-recipes/roles"
# chef.data_bags_path = "../my-recipes/data_bags"
# chef.add_recipe "mysql"
# chef.add_role "web"
#
# # You may also specify custom JSON attributes:
# chef.json = { :mysql_password => "foo" }
# end
# Enable provisioning with chef server, specifying the chef server URL,
# and the path to the validation key (relative to this Vagrantfile).
#
# The Opscode Platform uses HTTPS. Substitute your organization for
# ORGNAME in the URL and validation key.
#
# If you have your own Chef Server, use the appropriate URL, which may be
# HTTP instead of HTTPS depending on your configuration. Also change the
# validation key to validation.pem.
#
# config.vm.provision "chef_client" do |chef|
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
# chef.validation_key_path = "ORGNAME-validator.pem"
# end
#
# If you're using the Opscode platform, your validator client is
# ORGNAME-validator, replacing ORGNAME with your organization name.
#
# If you have your own Chef Server, the default validation client name is
# chef-validator, unless you changed the configuration.
#
# chef.validation_client_name = "ORGNAME-validator"
end