forked from python/psf-salt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
130 lines (108 loc) · 4.31 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
#!/usr/bin/env ruby
SERVERS = [
"backup-server",
{:name => "bugs", :box => "ubuntu/xenial64", :codename => "xenial", :ports => [8080]},
"cdn-logs",
"consul",
"docs",
"downloads",
"hg",
"jython-web",
{:name => "loadbalancer", :ports => [20000, 20001, 20002, 20003, 20004, 20005, 20100]},
"monitoring",
"packages",
"planet",
{:name => "postgresql-primary", :roles => ["postgresql", "postgresql-primary"]},
{:name => "postgresql-replica", :roles => ["postgresql", "postgresql-replica"]},
"speed-web",
"tracker",
"pypa-web",
"wiki",
]
SUBNET1 = "192.168.50"
SUBNET2 = "192.168.60"
MASTER1 = "#{SUBNET1}.2"
MASTER2 = "#{SUBNET2}.2"
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.define "salt-master" do |s_config|
s_config.vm.hostname = "salt-master.vagrant.psf.io"
s_config.vm.network "private_network", ip: MASTER1, virtualbox__intnet: "psf1"
s_config.vm.network "private_network", ip: MASTER2, virtualbox__intnet: "psf2"
s_config.vm.provider "virtualbox" do |v|
v.memory = 1024
v.cpus = 2
end
s_config.vm.synced_folder "salt/", "/srv/salt/"
s_config.vm.synced_folder "pillar/", "/srv/pillar/"
# Provision the salt-master.
s_config.vm.provision :shell, :inline => <<-HEREDOC
wget -O - https://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -
echo 'deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest trusty main' > /etc/apt/sources.list.d/saltstack.list
HEREDOC
s_config.vm.provision :shell, :inline => <<-HEREDOC
apt-get update
apt-get install -y salt-master
ln -sf /vagrant/conf/vagrant/master.conf /etc/salt/master.d/local.conf
HEREDOC
# Run this always to make sure salt-master is running
s_config.vm.provision :shell, inline: "service salt-master restart", run: "always"
# Provision the salt-minion
s_config.vm.provision :shell, :inline => <<-HEREDOC
apt-get install -y salt-minion
echo 'master: #{MASTER1}\n' > /etc/salt/minion.d/local.conf
service salt-minion restart
salt-call state.highstate
HEREDOC
# Run this always, because we need to sync our states.
s_config.vm.provision :shell, inline: "salt-call state.highstate", run: "always"
end
SERVERS.each_with_index do |server_c, num|
if server_c.instance_of?(Hash)
server = server_c[:name]
roles = server_c.fetch :roles, [server]
box = server_c.fetch :box, nil
codename = server_c.fetch :codename, "trusty"
ports = server_c.fetch :ports, []
else
server = server_c
roles = [server_c]
box = nil
codename = "trusty"
ports = []
end
config.vm.define server, autostart: false do |s_config|
if box
s_config.vm.box = box
end
s_config.vm.hostname = "#{server}.vagrant.psf.io"
s_config.vm.network "private_network", ip: "#{SUBNET1}.#{num + 10}", virtualbox__intnet: "psf1"
s_config.vm.network "private_network", ip: "#{SUBNET2}.#{num + 10}", virtualbox__intnet: "psf2"
ports.each do |port|
s_config.vm.network "forwarded_port", guest: port, host: port
end
# Provision the salt-minion
if codename == "trusty"
s_config.vm.provision :shell, :inline => <<-HEREDOC
wget -O - https://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -
echo 'deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest trusty main' > /etc/apt/sources.list.d/saltstack.list
HEREDOC
end
if codename == "xenial"
s_config.vm.provision :shell, :inline => <<-HEREDOC
wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -
echo 'deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/latest xenial main' > /etc/apt/sources.list.d/saltstack.list
HEREDOC
end
s_config.vm.provision :shell, :inline => <<-HEREDOC
apt-get update
apt-get install -y salt-minion
echo 'master: #{MASTER1}\n' > /etc/salt/minion.d/local.conf
service salt-minion restart
salt-call state.highstate
HEREDOC
# Run this always, because we need to sync our states.
s_config.vm.provision :shell, inline: "salt-call state.highstate", run: "always"
end
end
end