From 0c1548fbd87591f4eb736575334592714fef385a Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sun, 24 Dec 2023 12:54:09 +1100 Subject: [PATCH] feat: add new datavol - add datavol define to replace the datavol class, which has more flexibility through additional params, and the ability to call it multiple times for multiple datavolumes --- site/profiles/manifests/storage/datavol.pp | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 site/profiles/manifests/storage/datavol.pp diff --git a/site/profiles/manifests/storage/datavol.pp b/site/profiles/manifests/storage/datavol.pp new file mode 100644 index 0000000..ecc9a9d --- /dev/null +++ b/site/profiles/manifests/storage/datavol.pp @@ -0,0 +1,75 @@ +# profiles::storage::datavol +# +# This define 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. +# +define profiles::storage::datavol ( + Enum['present', 'absent'] $ensure = 'present', + Enum['ext2', 'ext3', 'ext4', 'xfs', 'btrfs'] $fstype = 'xfs', + String $vg = 'datavg', + String $pv = '/dev/vdb', + String $lv = 'data', + String $owner = 'root', + String $group = 'root', + Stdlib::Filemode $mode = '0755', + 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 => $owner, + group => $group, + mode => $mode, + } + + # 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}"], + } +}