-
Notifications
You must be signed in to change notification settings - Fork 31
/
Vagrantfile
175 lines (144 loc) · 5.57 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
$enable_serial_logging = false
raise "vagrant-vbguest plugin must be installed" unless Vagrant.has_plugin? "vagrant-vbguest"
Vagrant.configure("2") do |config|
# Sync time with the local host
config.vm.provider 'virtualbox' do |vb|
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ]
end
# sync build folder
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.synced_folder 'scripts/vagrant/', '/scripts/', create: true
config.vm.synced_folder 'build/', '/banzaicloud/', create: true
$num_instances = 4
# almalinux 8 nodes
(1..$num_instances).each do |n|
config.vm.define "almalinux#{n}" do |node|
node.vm.box = "boxomatic/almalinux-8"
node.vm.box_version = "20220116.0.1"
class Foo < VagrantVbguest::Installers::Linux
def install_kernel_devel(opts=nil, &block)
cmd = "dnf update kernel -y"
communicate.sudo(cmd, opts, &block)
cmd = "dnf install -y kernel-devel"
communicate.sudo(cmd, opts, &block)
cmd = "shutdown -r now"
communicate.sudo(cmd, opts, &block)
begin
sleep 5
end until @vm.communicate.ready?
end
end
node.vbguest.installer = Foo
node.vm.network "private_network", ip: "192.168.64.#{n+10}"
node.vm.hostname = "almalinux#{n}"
node.vm.provider "virtualbox" do |vb|
vb.name = "almalinux#{n}"
vb.memory = "2048"
vb.cpus = "2"
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
end
node.vm.provision "shell" do |s|
s.inline = <<-SHELL
dnf install -y yum-utils wget curl chrony vim net-tools socat
echo 'sync time'
systemctl enable --now chronyd
swapoff -a
modprobe ip_tables
echo 'ip_tables' >> /etc/modules-load.d/iptables.conf
echo 'set host name resolution'
cat >> /etc/hosts <<EOF
192.168.64.11 almalinux1
192.168.64.12 almalinux2
192.168.64.13 almalinux3
192.168.64.14 almalinux4
EOF
cat /etc/hosts
hostnamectl set-hostname almalinux#{n}
SHELL
end
end
end
# Ubuntu LTS nodes
(1..$num_instances).each do |n|
config.vm.define "ubuntu#{n}" do |node|
node.vm.box = "ubuntu/focal64"
node.vm.network "private_network", ip: "192.168.64.#{n+20}"
node.vm.hostname = "ubuntu#{n}"
node.vm.provider "virtualbox" do |vb|
vb.name = "ubuntu#{n}"
vb.memory = "2048"
vb.cpus = "2"
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
end
node.vm.provision "shell" do |s|
s.inline = <<-SHELL
apt-get update
apt-get install -y ntp wget curl vim net-tools socat
echo 'sync time'
systemctl start ntp
systemctl enable ntp
echo 'set host name resolution'
cat >> /etc/hosts <<EOF
192.168.64.21 ubuntu1
192.168.64.22 ubuntu2
192.168.64.23 ubuntu3
192.168.64.24 ubuntu4
EOF
cat /etc/hosts
hostnamectl set-hostname ubuntu#{n}
SHELL
end
end
end
config.vm.define "ubuntu-docker-focal" do |node|
node.vm.box = "ubuntu/focal64"
node.vm.network "private_network", ip: "192.168.64.30"
node.vm.hostname = "ubuntu-docker"
node.vm.provider "virtualbox" do |vb|
vb.name = "ubuntu-docker"
vb.memory = "2048"
vb.cpus = "2"
vb.customize ["modifyvm", :id, "--audio", "none"]
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
end
node.vm.provision "shell" do |s|
s.inline = <<-SHELL
apt-get update
apt-get install -y ntp wget curl vim net-tools socat
echo 'sync time'
systemctl start ntp
systemctl enable ntp
echo 'set host name resolution'
cat >> /etc/hosts <<EOF
192.168.64.30 ubuntu-docker
EOF
cat /etc/hosts
hostnamectl set-hostname ubuntu-docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update && apt-get install -y \
containerd.io=1.4.3-1 \
docker-ce=5:20.10.1~3-0~ubuntu-$(lsb_release -cs) \
docker-ce-cli=5:20.10.1~3-0~ubuntu-$(lsb_release -cs)
cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
systemctl daemon-reload
systemctl restart docker
SHELL
end
end
end