Enhanced variable handling

- Load variables from .vagrant_settings
- Provide default values
This commit is contained in:
Kris Lamoureux 2023-06-13 02:04:30 -04:00
parent b3e232451c
commit f68117d9a0
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
2 changed files with 29 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.vagrant .vagrant
.vagrant_settings
.vscode .vscode

34
Vagrantfile vendored
View File

@ -1,12 +1,34 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Load overrides
require 'yaml'
settings_path = '.vagrant_settings'
settings = {}
if File.exist?(settings_path)
settings = YAML.load_file(settings_path)
end
VAGRANT_CPUS = settings["VAGRANT_CPUS"] || 2
VAGRANT_MEMORY = settings["VAGRANT_MEMORY"] || 4096
VAGRANT_NETWORK_NAME = settings["VAGRANT_NETWORK_NAME"] || "vagrant-libvirt"
VAGRANT_NETWORK_ADDR = settings["VAGRANT_NETWORK_ADDR"] || "192.168.121.0/24"
# Vagrant
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.box = "debian/bookworm64" config.vm.box = "debian/bookworm64"
config.vm.network "private_network", type: "dhcp" config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.synced_folder ".", "/vagrant", disabled: true
# Libvrit settings # Libvirt settings
config.vm.provider :libvirt do |domain| config.vm.provider :libvirt do |libvirt|
domain.memory = 4096 libvirt.cpu_mode = "host-model"
domain.cpus = 2 libvirt.cpus = VAGRANT_CPUS
libvirt.memory = VAGRANT_MEMORY
libvirt.management_network_name = VAGRANT_NETWORK_NAME
libvirt.management_network_address = VAGRANT_NETWORK_ADDR
libvirt.nested = true
end end
# Boot with a GUI in VirtualBox # Boot with a GUI in VirtualBox
@ -14,8 +36,8 @@ Vagrant.configure("2") do |config|
vbox.customize ["modifyvm", :id, "--vram", "128", vbox.customize ["modifyvm", :id, "--vram", "128",
"--graphicscontroller", "vboxvga", "--graphicscontroller", "vboxvga",
"--accelerate3d", "on"] "--accelerate3d", "on"]
vbox.memory = 4096 vbox.memory = VAGRANT_MEMORY
vbox.cpus = 2 vbox.cpus = VAGRANT_CPUS
vbox.gui = true vbox.gui = true
end end