khuedoan-homelab/metal/Vagrantfile
2022-02-11 21:37:10 +07:00

48 lines
1.3 KiB
Ruby

require 'yaml'
inventory = YAML.load_file(File.join(__dir__, './inventories/dev.yml'))
group_vars = YAML.load_file(File.join(__dir__, './group_vars/all.yml'))
# ANCHOR: vm_specs
cpus = 2
memory = "8192"
disk_size = "128GB"
# ANCHOR_END: vm_specs
Vagrant.configure("2") do |config|
config.vm.box = "rockylinux/8"
inventory['metal']['children'].each do |group, properties|
properties['hosts'].each do |host, host_vars|
config.vm.define host do |node|
ip = host_vars['ansible_host']
node.vm.network "public_network", ip: ip
node.vm.hostname = host
node.vm.disk :disk, size: disk_size, primary: true
end
end
end
config.vm.provider "virtualbox" do |vb|
vb.cpus = cpus
vb.memory = memory
end
config.vm.provision "file",
source: "#{group_vars['ansible_ssh_private_key_file']}.pub",
destination: "/tmp/id_ed25519.pub"
# TODO move most of this to Ansible?
config.vm.provision "shell",
reboot: true,
inline: <<-SHELL
mkdir /#{group_vars['ansible_user']}/.ssh
cat /tmp/id_ed25519.pub >> ~#{group_vars['ansible_user']}/.ssh/authorized_keys
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
dnf install -y iscsi-initiator-utils
systemctl enable --now iscsid
sysctl fs.inotify.max_user_instances=8192
sysctl -p
SHELL
end