This repository has been archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Vagrantfile
67 lines (55 loc) · 2.18 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
# look up system cpu and ram so we can use more intelligent defaults
LINUX = RUBY_PLATFORM =~ /linux/
OSX = RUBY_PLATFORM =~ /darwin/
PROD_CPUS = 1
PROD_MEM = 500
if OSX
CPUS = `sysctl -n hw.ncpu`.to_i
MEM = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4
elsif LINUX
CPUS = `nproc`.to_i
MEM = `sed -n -e '/^MemTotal/s/^[^0-9]*//p' /proc/meminfo`.to_i / 1024 / 4
end
if defined?(CPUS)
CPUS = [CPUS, PROD_CPUS].min
else
CPUS = PROD_CPUS
end
if defined?(MEM)
MEM = [MEM, PROD_MEM].min
else
MEM = PROD_MEM
end
# use (faster) nfs sharing on osx only
SHARING = OSX ? { nfs: true } : nil
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-16.04"
# Allow the project directory to be accessible inside the Vagrant box.
# This should match the Ansible host_vars/vagrant synced_folder value.
config.vm.synced_folder '.', '/mnt/vagrant', SHARING
# Ideally, this IP will be unique, so the entry added to /etc/hosts won't
# conflict with that of another project.
config.vm.network :private_network, ip: '192.168.33.111'
# Automatically add an entry to /etc/hosts for this Vagrant box (requires
# sudo). This should match the Ansible host_vars/vagrant site_fqdn value.
config.hostsupdater.aliases = ['wptdash.loc']
# give vm access to 1/4 total system memory and all cpu
config.vm.provider 'virtualbox' do |v|
v.customize ['modifyvm', :id, '--memory', MEM] if defined?(MEM)
v.customize ['modifyvm', :id, '--cpus', CPUS] if defined?(CPUS)
v.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
# A specific name looks much better than "default" in ansible output.
config.vm.define 'vagrant'
# The Vagrant ansible provisioner is used here for convenience. Instead of
# the following code, the Vagrant box may be provisioned manually with
# ansible-playbook (like in production), but adding this code saves the
# trouble of having to run ansible-playbook manually after "vagrant up".
config.vm.provision "ansible" do |ansible|
# Run init playbook (which runs base, configure, vagrant-link playbooks).
ansible.playbook = "ansible/init.yml"
end
end