-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Vagrantfile
120 lines (99 loc) · 3.81 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 = [
{:name => "backup-server", :codename => "noble"},
{:name => "bugs", :codename => "jammy", :ports => [8080]},
{:name => "buildbot", :codename => "noble"},
"cdn-logs",
{:name => "codespeed", :codename => "jammy"},
{:name => "consul", :codename => "jammy"},
{:name => "docs", :codename => "noble"},
{:name => "downloads", :codename => "noble"},
{:name => "hg", :codename => "noble"},
{:name => "loadbalancer", :codename => "noble", :ports => [20000, 20001, 20002, 20003, 20004, 20005, 20010, 20011]},
"mail",
"moin",
"planet",
"pythontest",
]
SUBNET1 = "192.168.50"
SUBNET2 = "192.168.60"
MASTER1 = "#{SUBNET1}.2"
MASTER2 = "#{SUBNET2}.2"
Vagrant.configure("2") do |config|
config.vm.provider "docker" do |docker, override|
override.ssh.insert_key = true
docker.build_dir = 'dockerfiles'
docker.dockerfile = 'Dockerfile.focal'
docker.has_ssh = true
docker.remains_running = true
docker.privileged = true
end
config.vm.define "salt-master" do |s_config|
s_config.vm.provider "docker" do |docker, override|
docker.build_dir = "dockerfiles"
docker.dockerfile = "Dockerfile.jammy"
end
s_config.vm.hostname = "salt-master.vagrant.psf.io"
s_config.vm.network "private_network", ip: MASTER1
s_config.vm.network "private_network", ip: MASTER2
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
apt-get update
apt-get install -y salt-master python3-openssl
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
while ! salt-call consul.cluster_ready | grep True; do echo 'waiting for consul'; sleep 1; done
salt '*' saltutil.sync_all
salt '*' saltutil.refresh_grains
salt '*' saltutil.refresh_pillar wait=True timeout=30
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]
codename = server_c.fetch :codename, "focal"
ports = server_c.fetch :ports, []
else
server = server_c
roles = [server_c]
codename = "focal"
ports = []
end
config.vm.define server, autostart: false do |s_config|
s_config.vm.provider "docker" do |d|
d.build_dir = "dockerfiles"
d.dockerfile = "Dockerfile." + codename
end
s_config.vm.hostname = "#{server}.vagrant.psf.io"
s_config.vm.network "private_network", ip: "#{SUBNET1}.#{num + 10}"
s_config.vm.network "private_network", ip: "#{SUBNET2}.#{num + 10}"
ports.each do |port|
s_config.vm.network "forwarded_port", guest: port, host: port
end
# Provision the salt-minion
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