forked from python/psf-salt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
120 lines (98 loc) · 3.91 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
#!/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]},
"planet",
{:name => "postgresql-primary", :roles => ["postgresql", "postgresql-primary"]},
{:name => "postgresql-replica", :roles => ["postgresql", "postgresql-replica"]},
"speed-web",
"pypa-web",
]
SUBNET1 = "192.168.50"
SUBNET2 = "192.168.60"
MASTER1 = "#{SUBNET1}.2"
MASTER2 = "#{SUBNET2}.2"
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
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/py3/ubuntu/18.04/amd64/2018.3/SALTSTACK-GPG-KEY.pub | apt-key add -
echo 'deb http://repo.saltstack.com/py3/ubuntu/18.04/amd64/2018.3 bionic 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, "bionic"
ports = server_c.fetch :ports, []
else
server = server_c
roles = [server_c]
box = nil
codename = "bionic"
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 == "bionic"
s_config.vm.provision :shell, :inline => <<-HEREDOC
wget -O - https://repo.saltstack.com/py3/ubuntu/18.04/amd64/2018.3/SALTSTACK-GPG-KEY.pub | apt-key add -
echo 'deb http://repo.saltstack.com/py3/ubuntu/18.04/amd64/2018.3 bionic 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