feat: lxc compatability with datavol (#263)

- lxc doesnt mount block devices, just check for mountpoint

Reviewed-on: https://git.query.consul/unkinben/puppet-prod/pulls/263
This commit is contained in:
Ben Vincent 2025-04-26 17:28:57 +10:00
parent 78f4d2a88f
commit e4166c6b14

View File

@ -2,6 +2,9 @@
#
# This class manages the creation of a logical volume using the `lvm::volume` definition.
#
# For LXC hosts, this is replaced with a mount added from the host os. This class will simply check the
# mountpoint exists.
#
# Parameters:
# $ensure - Ensure whether the logical volume is present or not. Defaults to 'present'.
# $vg - Volume group name. No default.
@ -25,33 +28,48 @@ class profiles::base::datavol (
]] $mount_options = ['noatime', 'nodiratime'],
) {
# Ensure the physical volume exists
physical_volume { $pv:
ensure => $ensure,
before => Volume_group[$vg],
}
if $facts['virtual'] != 'lxc' {
# Ensure the volume group exists
volume_group { $vg:
ensure => $ensure,
physical_volumes => [$pv],
before => Logical_volume[$lv],
}
# Ensure the physical volume exists
physical_volume { $pv:
ensure => $ensure,
before => Volume_group[$vg],
}
# Ensure the logical volume exists
logical_volume { $lv:
ensure => $ensure,
volume_group => $vg,
size => $size,
before => Filesystem["/dev/${vg}/${lv}"],
}
# Ensure the volume group exists
volume_group { $vg:
ensure => $ensure,
physical_volumes => [$pv],
before => Logical_volume[$lv],
}
# Ensure the filesystem is created on the logical volume
filesystem { "/dev/${vg}/${lv}":
ensure => $ensure,
fs_type => $fstype,
require => Logical_volume[$lv],
before => Mount[$mount],
# Ensure the logical volume exists
logical_volume { $lv:
ensure => $ensure,
volume_group => $vg,
size => $size,
before => Filesystem["/dev/${vg}/${lv}"],
}
# Ensure the filesystem is created on the logical volume
filesystem { "/dev/${vg}/${lv}":
ensure => $ensure,
fs_type => $fstype,
require => Logical_volume[$lv],
before => Mount[$mount],
}
# Ensure the logical volume is mounted at the desired location
mount { $mount:
ensure => $mountstate,
device => "/dev/${vg}/${lv}",
fstype => $fstype,
options => $mount_options.join(','),
require => [
Filesystem["/dev/${vg}/${lv}"],
File[$mount]
],
}
}
# Ensure the mountpath exists
@ -62,12 +80,4 @@ class profiles::base::datavol (
mode => '0755',
}
# Ensure the logical volume is mounted at the desired location
mount { $mount:
ensure => $mountstate,
device => "/dev/${vg}/${lv}",
fstype => $fstype,
options => $mount_options.join(','),
require => Filesystem["/dev/${vg}/${lv}"],
}
}