Skip to content

Commit

Permalink
refactor virtual_machine
Browse files Browse the repository at this point in the history
Move $build to a case statement
  • Loading branch information
rrotter committed Jan 21, 2025
1 parent 0f64637 commit 9e06675
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions manifests/virtual_machine.pp
Original file line number Diff line number Diff line change
Expand Up @@ -103,43 +103,46 @@
}
} else {
# If the VM does not already exist, create it.
if $build == 'bullseye' {
file { "${tmpdir}/preseed.cfg":
content => template("nebula/virtual_machine/${build}.cfg.erb"),
}
case $build {
'bullseye': {
file { "${tmpdir}/preseed.cfg":
content => template("nebula/virtual_machine/${build}.cfg.erb"),
}

$initrd_inject = "--initrd-inject '${tmpdir}/preseed.cfg'"
}
$initrd_inject = "--initrd-inject '${tmpdir}/preseed.cfg'"

exec { "${prefix}::virt-install":
require => [
Package['libvirt-clients'],
Package['virtinst'],
File["${tmpdir}/preseed.cfg"],
],
creates => $full_image_path,
timeout => $timeout,
path => [
'/usr/bin',
'/usr/sbin',
'/bin',
'/sbin',
],
command => @("VIRT_INSTALL_EOF")
/usr/bin/virt-install \
-n '${title}' \
-r ${ram_in_mb} \
--vcpus ${cpus} \
--location ${location} \
--os-type=linux \
--disk '${full_image_path},size=${disk}' \
--network bridge=${internet_bridge},model=virtio \
--network bridge=${lan_bridge},model=virtio \
--console pty,target_type=virtio \
--virt-type kvm \
--graphics vnc ${initrd_inject} \
--extra-args 'auto netcfg/disable_dhcp=true'
| VIRT_INSTALL_EOF
exec { "${prefix}::virt-install":
require => [
Package['libvirt-clients'],
Package['virtinst'],
File["${tmpdir}/preseed.cfg"],
],
creates => $full_image_path,
timeout => $timeout,
path => [
'/usr/bin',
'/usr/sbin',
'/bin',
'/sbin',
],
command => @("VIRT_INSTALL_EOF")
/usr/bin/virt-install \
-n '${title}' \
-r ${ram_in_mb} \
--vcpus ${cpus} \
--location ${location} \
--os-type=linux \
--disk '${full_image_path},size=${disk}' \
--network bridge=${internet_bridge},model=virtio \
--network bridge=${lan_bridge},model=virtio \
--console pty,target_type=virtio \
--virt-type kvm \
--graphics vnc ${initrd_inject} \
--extra-args 'auto netcfg/disable_dhcp=true'
| VIRT_INSTALL_EOF
}
}
default: { fail("${build} is not a supported build type.") }
}
}

Expand Down

0 comments on commit 9e06675

Please sign in to comment.