-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
010.Vagrantfile
121 lines (103 loc) · 4.78 KB
/
010.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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# https://superuser.com/questions/895123/setting-up-our-existing-vagrant-virtualbox-instance-to-use-vpn-when-not-in-the
# Developer specific settings
developer = ENV['VAGRANT_DEV']
example_path = ENV['VAGRANT_REPO']
# Perform a quick sanity check, to ensure everything actually is set up.
if developer.empty? or example_path.empty? then
puts "Developer or example path not set"
exit
end
# Vagrant settings
Vagrant.configure("2") do |config|
{
# Define which VMs to run
'dev' => {
:roles => ["devbox"]
},
# 'web' => {
# :roles => ["webworker", "queue", "cron"],
# :use_remote_git => true
# }
}.each do |name, cfg|
# Enable the hostmanager plugin (Only works with VirtualBox on OS X/Linux)
if Vagrant.has_plugin?("vagrant-hostmanager") then
config.vm.provision :hostmanager do
config.hostmanager.enabled = false
config.hostmanager.manage_host = true
config.hostmanager.include_offline = false
end
end
config.vm.define name do |vm_config|
# Give the box enough memory, more CPUs, etc.
vm_config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
# Set up the host computer's hosts file
if Vagrant.has_plugin?("vagrant-hostmanager") then
config.vm.provision :hostmanager do
if cfg.has_key?(:roles) and cfg[:roles].include?("devbox") then
vm_config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
if vm.id
`VBoxManage guestproperty get #{vm.id} "/VirtualBox/GuestInfo/Net/1/V4/IP"`.split()[1]
end
end
vm_config.hostmanager.aliases = Dir.glob(example_path + '/www/clients/*/sites/*').each { |d| d.replace(d.gsub(/.*\/sites\//,"") + "." + developer + ".bc") }
end
end
end
end
# General VM setup
#vm_config.vm.network :public_network
vm_config.vm.network :private_network, ip: "172.21.1.180"
vm_config.vm.box = name
vm_config.vm.hostname = "#{name}-#{developer}"
vm_config.vm.box_url = "http://vagrant.office.example.com/package.box"
# Share the host machine's example folder with the VM
vm_config.vm.synced_folder example_path, "/example",
:mount_options => ["dmode=777","fmode=666"]
# Tell the OS to use eth1 as the default route, which results in Chef getting the correct IP.
config.vm.provision :shell, run: "always", inline: <<-SCRIPT
sudo route del default || true # Make sure we delete the current default route.
sudo route add default gw 172.20.0.1 || true
if [[ ! -d "/etc/chef" ]] ; then sudo mkdir /etc/chef; fi
if [[ ! -f "/etc/chef/webworker.key" ]] ; then sudo wget -O/etc/chef/webworker.key http://vagrant.office.example.com/webworker.key 2>/dev/null; fi
SCRIPT
# Provision with Chef
vm_config.vm.provision :chef_client do |chef|
# Set up chef config
chef.chef_server_url = "https://chef.internal.office.example.com/"
chef.validation_key_path = "validation.pem"
chef.environment = "internal"
chef.node_name = "#{name}-#{developer}"
# Chef attributes
chef.json = {
"example" => {
"example_deployed_path" => "/example/",
"devbox" => {
"developer" => developer
}
},
"chef_client" =>{
"config" => {
"node_name" => "#{name}-#{developer}"
}
}
}
if cfg.has_key?(:use_remote_git) and cfg[:use_remote_git] then
chef.json['example'].delete('example_deployed_path')
end
# Add roles
chef.add_role "example-base"
if cfg.has_key?(:roles) then
cfg[:roles].each do |role|
chef.add_role role
end
end
end
end
end
end