Update Vagrantfile to use external settings

This commit is contained in:
Kris Lamoureux 2023-08-21 18:46:47 -04:00
parent ef5aacdbbd
commit 9b5be29a1a
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
2 changed files with 25 additions and 24 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
.playbook .playbook
.vagrant .vagrant*
.vscode .vscode
/environments/ /environments/

47
Vagrantfile vendored
View File

@ -1,43 +1,45 @@
# -*- mode: ruby -*- # -*- mode: ruby -*-
# vi: set ft=ruby : # vi: set ft=ruby :
SSH_FORWARD=ENV["SSH_FORWARD"] require 'yaml'
if !(SSH_FORWARD == "true") settings_path = '.vagrant.yml'
SSH_FORWARD = false settings = {}
if File.exist?(settings_path)
settings = YAML.load_file(settings_path)
end end
VAGRANT_BOX = settings['VAGRANT_BOX'] || 'debian/bookworm64'
VAGRANT_CPUS = settings['VAGRANT_CPUS'] || 2
VAGRANT_MEM = settings['VAGRANT_MEM'] || 2048
SSH_FORWARD = settings['SSH_FORWARD'] || false
# Default to shell environment variable: PLAYBOOK (priority #1)
PLAYBOOK=ENV["PLAYBOOK"] PLAYBOOK=ENV["PLAYBOOK"]
if !PLAYBOOK if !PLAYBOOK
if File.exist?('.playbook') # PLAYBOOK setting in .vagrant.yml (priority #2)
PLAYBOOK = IO.read('.playbook').split("\n")[0] PLAYBOOK = settings['PLAYBOOK'] || false
end
if !PLAYBOOK || PLAYBOOK.empty? if !PLAYBOOK || PLAYBOOK.empty?
PLAYBOOK = "\nERROR: Set env PLAYBOOK" puts "[VAGRANTFILE ERROR]: Set PLAYBOOK setting in .vagrant.yml"
abort
end end
else
File.write(".playbook", PLAYBOOK)
end end
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.box = "debian/bullseye64" config.vm.box = VAGRANT_BOX
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 "./scratch", "/vagrant/scratch"
config.ssh.forward_agent = SSH_FORWARD config.ssh.forward_agent = SSH_FORWARD
# Machine Name # Libvrit provider
config.vm.define :moxie do |moxie| #
end
config.vm.provider :libvirt do |libvirt| config.vm.provider :libvirt do |libvirt|
libvirt.cpus = 2 libvirt.cpus = VAGRANT_CPUS
libvirt.memory = 4096 libvirt.memory = VAGRANT_MEM
libvirt.default_prefix = ""
end end
config.vm.provider "virtualbox" do |vbox| # Virtualbox provider
vbox.memory = 4096 config.vm.provider :virtualbox do |vbox|
vbox.cpus = VAGRANT_CPUS
vbox.memory = VAGRANT_MEM
end end
# Provision with Ansible # Provision with Ansible
@ -46,5 +48,4 @@ Vagrant.configure("2") do |config|
ansible.compatibility_mode = "2.0" ansible.compatibility_mode = "2.0"
ansible.playbook = "dev/" + PLAYBOOK + ".yml" ansible.playbook = "dev/" + PLAYBOOK + ".yml"
end end
end end