2023-05-20 13:39:45 +02:00
|
|
|
# -*- mode: ruby -*-
|
|
|
|
# vi: set ft=ruby :
|
|
|
|
|
|
|
|
if ! ( ENV['SCULLERY_BOX_NAME'] && ENV['SCULLERY_BOX_IMAGE'] ) || ! ( ENV['SCULLERY_MASTERS'] || ENV['SCULLERY_MINIONS'] )
|
|
|
|
print('Missing parameters')
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
2023-05-20 17:51:32 +02:00
|
|
|
salt_bootstrap = ENV['SCULLERY_BOOTSTRAP']
|
2023-06-08 17:41:14 +02:00
|
|
|
salt_pillar = ENV['SCULLERY_PILLAR']
|
2023-05-20 17:51:32 +02:00
|
|
|
salt_file_roots = 'file_roots:\n base:\n - /srv/salt\n - /srv/formulas\n'
|
2023-05-20 13:39:45 +02:00
|
|
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.provider "libvirt"
|
|
|
|
config.vm.box = ENV['SCULLERY_BOX_NAME']
|
|
|
|
config.vm.box_url = ENV['SCULLERY_BOX_IMAGE']
|
|
|
|
config.vm.provision "shell", inline: <<-SHELL
|
2023-06-08 14:55:26 +02:00
|
|
|
if [ ! -f '/var/adm/scullery.configured' ]
|
|
|
|
then
|
|
|
|
systemctl restart network
|
|
|
|
touch /var/adm/scullery.configured
|
|
|
|
fi
|
2023-05-20 13:39:45 +02:00
|
|
|
SHELL
|
|
|
|
if ENV['SCULLERY_MASTERS']
|
|
|
|
ENV['SCULLERY_MASTERS'].split(',').each do |vmname|
|
|
|
|
config.vm.define "#{vmname}", primary: true do |master_config|
|
|
|
|
master_config.vm.hostname = "#{vmname}"
|
|
|
|
master_config.vm.provider :libvirt do |libvirt|
|
|
|
|
libvirt.memory = 768
|
|
|
|
end
|
2023-06-08 17:41:14 +02:00
|
|
|
master_config.vm.provision "shell", env: {'SALT_FILE_ROOTS': salt_file_roots, 'SALT_PILLAR': salt_pillar}, inline: <<-SHELL
|
2023-05-20 13:39:45 +02:00
|
|
|
printf 'auto_accept: True\n' > /etc/salt/master.d/notsecure.conf
|
2023-05-20 17:51:32 +02:00
|
|
|
printf "$SALT_FILE_ROOTS" > /etc/salt/master.d/roots.conf
|
2023-05-20 13:39:45 +02:00
|
|
|
systemctl enable --now salt-master
|
2023-06-08 17:41:14 +02:00
|
|
|
if [ -n "$SALT_PILLAR" -a -d "/vagrant/$SALT_PILLAR" ]
|
|
|
|
then
|
|
|
|
if [ -d '/srv/pillar' ]
|
|
|
|
then
|
|
|
|
rm -r /srv/pillar
|
|
|
|
fi
|
|
|
|
if [ ! -L '/srv/pillar' ]
|
|
|
|
then
|
|
|
|
ln -sv "/vagrant/$SALT_PILLAR" /srv/pillar
|
|
|
|
fi
|
|
|
|
fi
|
2023-05-20 13:39:45 +02:00
|
|
|
SHELL
|
2023-05-24 00:29:19 +02:00
|
|
|
if salt_bootstrap
|
|
|
|
master_config.vm.provision "shell", path: salt_bootstrap
|
|
|
|
end
|
2023-05-20 13:39:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if ENV['SCULLERY_MINIONS']
|
|
|
|
ENV['SCULLERY_MINIONS'].split(',').each do |vmname|
|
|
|
|
config.vm.define "#{vmname}" do |minion_config|
|
|
|
|
minion_config.vm.hostname = "#{vmname}"
|
|
|
|
if ENV['SCULLERY_MASTERS']
|
|
|
|
minion_config.vm.synced_folder '.', '/vagrant', disabled: true
|
|
|
|
minion_config.vm.provision "shell", inline: <<-SHELL
|
|
|
|
sed -i 's/^#master:.*/master: scullery-master0/' /etc/salt/minion
|
|
|
|
systemctl enable --now salt-minion
|
|
|
|
SHELL
|
|
|
|
else
|
2023-06-08 17:41:14 +02:00
|
|
|
minion_config.vm.provision "shell", env: {'SALT_FILE_ROOTS': salt_file_roots, 'SALT_PILLAR': salt_pillar}, inline: <<-SHELL
|
2023-05-20 17:51:32 +02:00
|
|
|
printf "$SALT_FILE_ROOTS" > /etc/salt/minion.d/roots.conf
|
2023-06-08 17:41:14 +02:00
|
|
|
if [ -n "$SALT_PILLAR" -a -d "/vagrant/$SALT_PILLAR" ]
|
|
|
|
then
|
|
|
|
if [ -d '/srv/pillar' ]
|
|
|
|
then
|
|
|
|
rm -r /srv/pillar
|
|
|
|
fi
|
|
|
|
if [ ! -L '/srv/pillar' ]
|
|
|
|
then
|
|
|
|
ln -sv "/vagrant/$SALT_PILLAR" /srv/pillar
|
|
|
|
fi
|
|
|
|
fi
|
2023-05-20 17:51:32 +02:00
|
|
|
SHELL
|
|
|
|
if salt_bootstrap
|
|
|
|
minion_config.vm.provision "shell", path: salt_bootstrap
|
|
|
|
end
|
2023-05-20 13:39:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|