-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVagrantfile.multi
More file actions
100 lines (80 loc) · 3.31 KB
/
Vagrantfile.multi
File metadata and controls
100 lines (80 loc) · 3.31 KB
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
domain = '-local.stackengine.com'
# location to mount go directory
guest = "/var/www/html/hello"
workstation = "~/code/vagrant_hello"
# Global provisioning. This stuff is needed on all machines
$globalscript = <<GLOBALSCRIPT
echo "#"
echo "# BEGIN Global Provisioning"
echo "#"
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install --assume-yes lxc-docker sqlite3 libsqlite3-dev s3cmd emacs23-nox avahi-daemon screen
sudo echo "US/Central" > /etc/timezone
sudo dpkg-reconfigure -f noninteractive tzdata
sudo /etc/init.d/cron stop
sudo /etc/init.dc/cron start
echo "#"
echo "# END Global Provisioning"
echo "#"
GLOBALSCRIPT
# Only happens on the leader
$leaderscript = <<LEADERSCRIPT
echo "# BEGIN LEADER PROVISIONING"
DEBIAN_FRONTEND=noninteractive apt-get install -y golang
echo "# END LEADER PROVISIONING"
LEADERSCRIPT
# Only happens on the followers
$followerscript = <<FOLLOWERSCRIPT
echo "# BEGIN FOLLOWER PROVISIONING"
echo "# END FOLLOWER PROVISIONING"
FOLLOWERSCRIPT
# Only happens on the clients
$clientscript = <<CLIENTSCRIPT
echo "# BEGIN CLIENT PROVISIONING"
echo "# END CLIENT PROVISIONING"
CLIENTSCRIPT
# What we want started up
nodes = [
{ :hostname => 'leader', :ip => '10.9.1.2', :mem => 2048, :cfg => $leaderscript},
{ :hostname => 'follower-01', :ip => '10.9.1.3', :cfg => $followerscript},
{ :hostname => 'follower-02', :ip => '10.9.1.4', :cfg => $followerscript},
{ :hostname => 'client-01',:ip => '10.9.1.5', :cfg => $clientscript},
]
#
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# setup et/host on boxes
config.hostmanager.enabled = true
nodes.each do |node|
config.vm.define node[:hostname] do |node_config|
node_config.vm.hostname = node[:hostname] + domain
node_config.hostmanager.aliases = node[:hostname]
node_config.vm.network :private_network, ip: node[:ip]
# default memory to 1G, allow hosts[] hash to override
memory = node[:mem] ? node[:mem] : 1024;
node_config.vm.provider :vmware_fusion do |v, override|
v.vmx["memsize"] = memory
v.vmx["numvcpus"] = 4
override.vm.box = 'https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vmwarefusion.box'
end
node_config.vm.provider :virtualbox do |vb, override|
vb.customize ['modifyvm', :id, '--memory', memory.to_s ]
override.vm.box = '~/vagrant_boxes/precise-server-cloudimg-amd64-vagrant-disk1.box'
end
# This will now run on _ALL_ the below defined virtual machines first
node_config.vm.provision :shell, inline: $globalscript
# now run custom configs
if node[:cfg]
node_config.vm.provision :shell, inline: node[:cfg]
end
# Mount the same shared directory for all the VMs so they can share the built binary
node_config.vm.synced_folder "#{workstation}", "#{guest}",
owner: 'vagrant', group: 'vagrant'
end
end
end