templates/vagrant/Vagrantfile.erb in falkorlib-0.8.10 vs templates/vagrant/Vagrantfile.erb in falkorlib-0.9.0
- old
+ new
@@ -1,8 +1,8 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
-# Time-stamp: <Mon 2020-04-20 15:32 svarrette>
+# Time-stamp: <Mon 2023-12-04 17:12 svarrette>
###########################################################################################
# __ __ _ __ _ _
# \ \ / /_ _ __ _ _ __ __ _ _ __ | |_ / _(_) | ___
# \ \ / / _` |/ _` | '__/ _` | '_ \| __| |_| | |/ _ \
# \ V / (_| | (_| | | | (_| | | | | |_| _| | | __/
@@ -23,11 +23,11 @@
# Terminal-table is a nice ruby gem for automatically print tables with nice layout
###
[ 'vagrant-hosts',
'vagrant-vbguest',
'vagrant-cachier',
- # 'vagrant-libvirt',
+ 'vagrant-libvirt',
'deep_merge',
'terminal-table' ].each do |plugin|
abort "Install the '#{plugin}' plugin with 'vagrant plugin install #{plugin}'" unless Vagrant.has_plugin?("#{plugin}")
end
require 'deep_merge'
@@ -51,27 +51,36 @@
### Default settings ###
DEFAULT_SETTINGS = {
# Default images settings
:defaults => {
:os => :<%= config[:os] %>,
+ :provider => :<%= config[:provider] %>,
:ram => <%= config[:ram] %>,
:vcpus => <%= config[:vcpus] %>,
- :vbguest_auto_update => true,
+ :vbguest_auto_update => false,
:role => 'default',
# :nodes => 1,
},
# Default domain settings
:network => {
:domain => '<%= config[:domain] %>',
:range => '<%= config[:range] %>',
},
# Default Boxes
:boxes => {
- :centos8 => '<%= config[:boxes][:centos8] %>',
- :centos7 => '<%= config[:boxes][:centos7] %>',
- :debian8 => '<%= config[:boxes][:debian8] %>',
- :ubuntu14 => '<%= config[:boxes][:ubuntu14] %>'
+ :debian12 => '<%= config[:boxes][:debian12] %>',
+ :debian12_uefi => '<%= config[:boxes][:debian12_uefi] %>',
+ :almalinux9 => '<%= config[:boxes][:almalinux9] %>',
+ :almalinux8 => '<%= config[:boxes][:almalinux8] %>',
+ :almalinux8_uefi => '<%= config[:boxes][:almalinux8_uefi] %>',
+ :rockylinux8 => '<%= config[:boxes][:rockylinux8] %>',
+ :centosstream9 => '<%= config[:boxes][:centosstream9] %>',
+ :centosstream8 => '<%= config[:boxes][:centosstream8] %>',
+ :ubuntu22 => '<%= config[:boxes][:ubuntu22] %>',
+ :ubuntu20 => '<%= config[:boxes][:ubuntu20] %>',
+ :fedora38 => '<%= config[:boxes][:fedora38] %>',
+ :archlinux => '<%= config[:boxes][:archlinux] %>'
},
# virtual images to deploy
# <name>:
# :hostname: <hostname>
# :desc: <VM-description>
@@ -124,22 +133,25 @@
# check if VirtualBox Guest Additions are up to date
if Vagrant.has_plugin?("vagrant-vbguest")
# set auto_update to false, if you do NOT want to check the correct
# additions version when booting these boxes
config.vbguest.auto_update = defaults[:vbguest_auto_update]
+ config.vbguest.installer_options = { allow_kernel_upgrade: true }
+
end
# Shell provisioner, to bootstrap each box with the minimal settings/packages
DEFAULT_PROVISIONING_SCRIPTS.each do |script|
config.vm.provision "shell", path: "#{script}", keep_color: true
end
- config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
+
+ # config.vm.synced_folder ".", "/vagrant", type: "virtualbox" # done by default
## Uncomment the below part if you want and additional shared directory
# config.vm.synced_folder "vagrant/shared", "/shared", mount_options: ['dmode=777','fmode=777'],
# type: "virtualbox" # Shared directory for users
if Dir.exist?(File.join(TOP_PUPPETDIR, 'hieradata'))
- config.vm.synced_folder "#{puppet_dir}/hieradata", "/tmp/vagrant-puppet/hieradata", type: "virtualbox"
+ config.vm.synced_folder "#{puppet_dir}/hieradata", "/tmp/vagrant-puppet/hieradata" #, type: "virtualbox"
end
# network settings
ipaddr = IPAddr.new network[:range]
ip_range = ipaddr.to_range.to_a
@@ -159,33 +171,58 @@
domain = network[:domain]
fqdn = "#{hostname}.#{domain}"
boxname = defaults[:os].to_s.downcase.gsub(/([^\d]+)(\d+)/, '\\1-\\2')
name = boxname if name == 'default'
os = node[:os] ? node[:os].to_sym : defaults[:os].to_sym
+ provider = (os =~ /_uefi$/)? 'libvirt' : defaults[:provider]
+ provider = node[:provider] if node[:provider]
ram = node[:ram] ? node[:ram] : defaults[:ram]
vcpus = node[:vcpus] ? node[:vcpus] : defaults[:vcpus]
role = node[:role] ? node[:role] : 'default'
desc = node[:desc] ? node[:desc] : 'n/a'
puppet_modules = node[:puppet_modules] ? node[:puppet_modules] : []
-
+ warn "provider: #{provider}"
abort "Non-existing box OS '#{os}' for the VM '#{name}'" if settings[:boxes][os.to_sym].nil?
abort "Empty IP address range" if ip_range.empty?
ip = ip_range[ ip_index.to_i ].to_s
ip_index += 1 # increment index for the next VM of this type
config.vm.define "#{name}" do |c|
c.vm.box = settings[:boxes][os.to_sym]
c.vm.hostname = "#{fqdn}"
- c.vm.network :private_network, :ip => ip
+ c.vm.network :private_network,
+ :ip => ip,
+ :libvirt__network_address => network[:range], # ip_range[0].to_s + '/24',
+ :libvirt__forward_mode => 'nat'
+
c.vm.provision :hosts, :sync_hosts => true
+ # (eventually) Force default provider
+ c.vm.provider :"#{provider}" if provider != 'virtualbox'
- c.vm.provider "virtualbox" do |v|
+ # Custom VM configs for virtualbox provider
+ c.vm.provider 'virtualbox' do |v|
v.customize [ 'modifyvm', :id, '--name', hostname, '--memory', ram.to_s ]
v.customize [ 'modifyvm', :id, '--cpus', vcpus.to_s ] if vcpus.to_i > 1
#v.customize [ 'setextradata', :id, 'VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root', '1']
+ v.customize ["modifyvm", :id, "--firmware", "efi"]
end
+ # Custom VM configs for libvirt provider
+ # see https://vagrant-libvirt.github.io/vagrant-libvirt/configuration.html
+ c.vm.provider :libvirt do |lv|
+ lv.uri = 'qemu:///system'
+ lv.host = hostname
+ lv.cpus = vcpus
+ lv.memory = ram
+ # lv.nested = true
+ # Emulated TPM
+ lv.tpm_model = "tpm-crb"
+ lv.tpm_type = "emulator"
+ lv.tpm_version = "2.0"
+
+ end
+
# role specialization
# if role == 'XX'
# c.vm.provision "shell" do |s|
# s.path = "scripts/XX_install.sh"
# s.args = [ '--debug' ]
@@ -199,12 +236,13 @@
config.vm.provision "shell",
inline: "puppet module install --target-dir /vagrant/#{PUPPET_MODULEDIR} #{mod}"
end
# A role fact MUST be defined (default: 'default') as it is used in Hiera config
+ facts_dir = '/etc/facter/facts.d/'
c.vm.provision "shell",
- inline: "echo '{ \"role\": \"#{role}\" }' > /opt/puppetlabs/facter/facts.d/custom.json",
+ inline: "mkdir -p #{facts_dir}; echo '{ \"role\": \"#{role}\" }' > #{facts_dir}/custom.json",
keep_color: true
################ Puppet install ##############
c.vm.provision "puppet" do |puppet|
puppet.options = [
'--verbose',
@@ -220,17 +258,17 @@
puppet.manifest_file = File.exists?("/vagrant/#{puppet_dir}/manifests/#{role}.pp") ? "#{role}.pp" : 'default.pp'
end # puppet
__table[:rows] << [ name, fqdn, os.to_sym, "#{vcpus}/#{ram}", role, desc, ip]
- if settings[:vms].keys.last == name
+ #if settings[:vms].keys.last == name
c.trigger.after :up do |trigger|
trigger.info = (Terminal::Table.new __table).to_s
trigger.warn = <<-EOF
- Virtual Vagrant infrastructure successfully deployed!
EOF
end
- end
+ #end
end # config.vm.define
end # settings
end