2023-03-14 18:58:52 +00:00
|
|
|
# -*- mode: ruby -*-
|
|
|
|
# vi: set ft=ruby :
|
|
|
|
|
|
|
|
# Salt lab environment with one master and four minions
|
|
|
|
|
2023-03-14 03:08:57 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.nfs.verify_installed = false
|
2023-03-24 19:45:04 +00:00
|
|
|
config.vm.synced_folder ".", "/vagrant", disabled: true
|
2023-03-14 03:08:57 +00:00
|
|
|
config.vm.define "salt", primary: true do |salt|
|
|
|
|
salt.vm.box = "peru/ubuntu-20.04-server-amd64"
|
|
|
|
salt.vm.hostname = "salt"
|
2023-03-14 18:58:52 +00:00
|
|
|
salt.vm.network "private_network", ip: "192.168.100.120"
|
2023-03-14 03:08:57 +00:00
|
|
|
salt.vm.provider :libvirt do |libvirt|
|
|
|
|
libvirt.memory = 1024
|
|
|
|
end
|
2023-04-08 03:38:21 +00:00
|
|
|
# salt.vm.synced_folder 'srv', '/srv', type: 'rsync'
|
2023-03-14 03:08:57 +00:00
|
|
|
salt.vm.provision "shell", inline: <<-SHELL
|
2023-03-23 23:37:36 +00:00
|
|
|
apt-get update
|
2023-04-08 03:38:21 +00:00
|
|
|
apt-get install curl vim python3-pygit2 -y
|
2023-03-14 03:08:57 +00:00
|
|
|
curl -o bootstrap-salt.sh -L https://bootstrap.saltproject.io
|
2023-03-24 19:44:50 +00:00
|
|
|
sh bootstrap-salt.sh -M -X -U
|
2023-03-27 02:10:41 +00:00
|
|
|
cat << EOF > /etc/salt/master.d/lab.conf
|
2023-04-08 03:38:21 +00:00
|
|
|
auto_accept:
|
2023-03-27 02:10:41 +00:00
|
|
|
file_roots:
|
|
|
|
base:
|
2023-04-08 03:38:21 +00:00
|
|
|
- /srv/
|
|
|
|
fileserver_backend:
|
|
|
|
- roots
|
|
|
|
- gitfs
|
|
|
|
gitfs_provider: pygit2
|
|
|
|
gitfs_update_interval: 60
|
2023-04-08 03:39:05 +00:00
|
|
|
gitfs_base: gitfs
|
2023-04-08 03:38:21 +00:00
|
|
|
gitfs_remotes:
|
|
|
|
- https://github.com/jbowdre/vagrant-saltlab.git:
|
|
|
|
- root: salt_content/salt
|
|
|
|
- mountpoint: salt://
|
|
|
|
ext_pillar:
|
|
|
|
- git:
|
|
|
|
- main https://github.com/jbowdre/vagrant-saltlab.git:
|
|
|
|
- root: pillar
|
2023-03-27 02:10:41 +00:00
|
|
|
reactor:
|
|
|
|
- 'salt/minion/*/start':
|
2023-04-08 03:38:21 +00:00
|
|
|
- salt://_reactor/sync_grains.sls
|
2023-03-27 02:10:41 +00:00
|
|
|
EOF
|
2023-03-23 23:37:06 +00:00
|
|
|
systemctl start salt-master
|
|
|
|
systemctl start salt-minion
|
|
|
|
sleep 5
|
|
|
|
systemctl restart salt-master
|
2023-03-14 03:08:57 +00:00
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
config.vm.define "minion01" do |minion01|
|
|
|
|
minion01.vm.box = "peru/ubuntu-20.04-server-amd64"
|
|
|
|
minion01.vm.hostname = "minion01"
|
2023-03-14 18:58:52 +00:00
|
|
|
minion01.vm.network "private_network", ip: "192.168.100.121"
|
2023-03-14 03:08:57 +00:00
|
|
|
minion01.vm.provision "shell", inline: <<-SHELL
|
2023-03-23 23:37:36 +00:00
|
|
|
apt-get update
|
2023-03-24 02:40:54 +00:00
|
|
|
apt-get install curl -y
|
2023-03-14 03:08:57 +00:00
|
|
|
curl -o bootstrap-salt.sh -L https://bootstrap.saltproject.io
|
2023-03-24 19:44:50 +00:00
|
|
|
sh bootstrap-salt.sh -A 192.168.100.120 -U
|
2023-03-24 02:40:54 +00:00
|
|
|
cat << EOF > /etc/salt/minion.d/grains.conf
|
|
|
|
grains:
|
|
|
|
roles:
|
|
|
|
- saltlab
|
|
|
|
EOF
|
|
|
|
systemctl restart salt-minion
|
2023-03-14 03:08:57 +00:00
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
config.vm.define "minion02" do |minion02|
|
|
|
|
minion02.vm.box = "debian/bullseye64"
|
|
|
|
minion02.vm.hostname = "minion02"
|
2023-03-14 18:58:52 +00:00
|
|
|
minion02.vm.network "private_network", ip: "192.168.100.122"
|
2023-03-14 03:08:57 +00:00
|
|
|
minion02.vm.provision "shell", inline: <<-SHELL
|
2023-03-23 23:37:36 +00:00
|
|
|
apt-get update
|
2023-03-24 02:40:54 +00:00
|
|
|
apt-get install curl -y
|
2023-03-14 03:08:57 +00:00
|
|
|
curl -o bootstrap-salt.sh -L https://bootstrap.saltproject.io
|
2023-03-24 19:44:50 +00:00
|
|
|
sh bootstrap-salt.sh -A 192.168.100.120 -U
|
2023-03-24 02:40:54 +00:00
|
|
|
cat << EOF > /etc/salt/minion.d/grains.conf
|
|
|
|
grains:
|
|
|
|
roles:
|
|
|
|
- saltlab
|
2023-03-24 22:12:03 +00:00
|
|
|
- web
|
2023-03-24 02:40:54 +00:00
|
|
|
EOF
|
|
|
|
systemctl restart salt-minion
|
2023-03-14 03:08:57 +00:00
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
config.vm.define "minion03" do |minion03|
|
|
|
|
minion03.vm.box = "generic/rocky9"
|
|
|
|
minion03.vm.hostname = "minion03"
|
2023-03-14 18:58:52 +00:00
|
|
|
minion03.vm.network "private_network", ip: "192.168.100.123"
|
2023-03-14 03:08:57 +00:00
|
|
|
minion03.vm.provision "shell", inline: <<-SHELL
|
2023-03-24 19:43:43 +00:00
|
|
|
echo -n "> Waiting for network..."
|
|
|
|
while ! host bootstrap.saltproject.io >/dev/null; do
|
|
|
|
echo -n "."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo "Proceeding!"
|
2023-03-14 03:08:57 +00:00
|
|
|
curl -o bootstrap-salt.sh -L https://bootstrap.saltproject.io
|
2023-03-24 19:44:50 +00:00
|
|
|
# workaround for EL > 9 (https://github.com/saltstack/salt-bootstrap/issues/1903)
|
|
|
|
sh bootstrap-salt.sh -A 192.168.100.120 -U -P -x python3 onedir
|
2023-03-25 03:08:20 +00:00
|
|
|
systemctl enable salt-minion
|
2023-03-24 02:40:54 +00:00
|
|
|
cat << EOF > /etc/salt/minion.d/grains.conf
|
|
|
|
grains:
|
|
|
|
roles:
|
|
|
|
- saltlab
|
|
|
|
EOF
|
|
|
|
systemctl restart salt-minion
|
2023-03-14 03:08:57 +00:00
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
config.vm.define "minion04" do |minion04|
|
|
|
|
minion04.vm.box = "generic/centos7"
|
|
|
|
minion04.vm.hostname = "minion04"
|
2023-03-14 18:58:52 +00:00
|
|
|
minion04.vm.network "private_network", ip: "192.168.100.124"
|
2023-03-14 03:08:57 +00:00
|
|
|
minion04.vm.provision "shell", inline: <<-SHELL
|
2023-03-24 19:43:43 +00:00
|
|
|
echo -n "> Waiting for network..."
|
|
|
|
while ! host bootstrap.saltproject.io >/dev/null; do
|
|
|
|
echo -n "."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo "Proceeding!"
|
2023-03-14 03:08:57 +00:00
|
|
|
curl -o bootstrap-salt.sh -L https://bootstrap.saltproject.io
|
2023-03-24 19:44:50 +00:00
|
|
|
sh bootstrap-salt.sh -A 192.168.100.120 -U
|
2023-03-24 02:40:54 +00:00
|
|
|
cat << EOF > /etc/salt/minion.d/grains.conf
|
|
|
|
grains:
|
|
|
|
roles:
|
|
|
|
- saltlab
|
2023-03-24 22:12:03 +00:00
|
|
|
- web
|
2023-04-05 02:09:08 +00:00
|
|
|
EOF
|
|
|
|
systemctl restart salt-minion
|
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
config.vm.define "app01" do |app01|
|
|
|
|
app01.vm.box = "peru/ubuntu-20.04-server-amd64"
|
|
|
|
app01.vm.hostname = "app01"
|
|
|
|
app01.vm.network "private_network", ip: "192.168.100.131"
|
|
|
|
app01.vm.provision "shell", inline: <<-SHELL
|
|
|
|
apt-get update
|
|
|
|
apt-get install curl -y
|
|
|
|
curl -o bootstrap-salt.sh -L https://bootstrap.saltproject.io
|
|
|
|
sh bootstrap-salt.sh -A 192.168.100.120 -U
|
|
|
|
cat << EOF > /etc/salt/minion.d/grains.conf
|
|
|
|
grains:
|
|
|
|
roles:
|
|
|
|
- acglab
|
|
|
|
EOF
|
|
|
|
systemctl restart salt-minion
|
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
config.vm.define "db-users" do |dbusers|
|
|
|
|
dbusers.vm.box = "generic/rocky9"
|
|
|
|
dbusers.vm.hostname = "db-users"
|
|
|
|
dbusers.vm.network "private_network", ip: "192.168.100.132"
|
|
|
|
dbusers.vm.provision "shell", inline: <<-SHELL
|
|
|
|
echo -n "> Waiting for network..."
|
|
|
|
while ! host bootstrap.saltproject.io >/dev/null; do
|
|
|
|
echo -n "."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo "Proceeding!"
|
|
|
|
curl -o bootstrap-salt.sh -L https://bootstrap.saltproject.io
|
|
|
|
# workaround for EL > 9 (https://github.com/saltstack/salt-bootstrap/issues/1903)
|
|
|
|
sh bootstrap-salt.sh -A 192.168.100.120 -U -P -x python3 onedir
|
|
|
|
systemctl enable salt-minion
|
|
|
|
cat << EOF > /etc/salt/minion.d/grains.conf
|
|
|
|
grains:
|
|
|
|
roles:
|
|
|
|
- acglab
|
2023-03-24 02:40:54 +00:00
|
|
|
EOF
|
|
|
|
systemctl restart salt-minion
|
2023-03-14 03:08:57 +00:00
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
end
|