puppet-prod/site/profiles/manifests/base/datavol.pp
Ben Vincent d11dcc0b24 fix: datavol profile doesnt create the mountpoint
- add file resource to create the required mountpath
- add Array[Enum[]] for mount_options
- fix mount to ensure the mount_options are used
- remove pass and dump options, leave as defaults
2023-11-06 19:31:35 +11:00

73 lines
2.1 KiB
Puppet

# profiles::base::datavol
#
# This class manages the creation of a logical volume using the `lvm::volume` definition.
#
# Parameters:
# $ensure - Ensure whether the logical volume is present or not. Defaults to 'present'.
# $vg - Volume group name. No default.
# $pv - Physical volume, typically the disk or partition device path. No default.
# $fstype - Filesystem type for the logical volume. Defaults to 'ext3'.
# $size - Size of the logical volume. undef = 100%FREE. Changing $size to cause a resize.
#
class profiles::base::datavol (
Enum['present', 'absent'] $ensure = 'present',
Enum['ext2', 'ext3', 'ext4', 'xfs', 'btrfs'] $fstype = 'xfs',
String $vg = 'datavg',
String $pv = '/dev/vdb',
String $lv = 'data',
Stdlib::Absolutepath $mount = '/data',
Optional[Variant[Pattern[/^\d+(M|G|T|P)$/], Integer]] $size = undef,
Array[Enum[
'defaults', 'ro', 'rw', 'sync', 'async',
'noatime', 'nodiratime', 'noexec', 'nosuid',
'nodev', 'remount', 'auto', 'noauto'
]] $mount_options = ['noatime', 'nodiratime'],
) {
# Ensure the physical volume exists
physical_volume { $pv:
ensure => $ensure,
before => Volume_group[$vg],
}
# Ensure the volume group exists
volume_group { $vg:
ensure => $ensure,
physical_volumes => [$pv],
before => Logical_volume[$lv],
}
# 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 mountpath exists
file { $mount:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
# Ensure the logical volume is mounted at the desired location
mount { $mount:
ensure => $ensure,
device => "/dev/${vg}/${lv}",
fstype => $fstype,
options => $mount_options.join(','),
require => Filesystem["/dev/${vg}/${lv}"],
}
}