puppet-prod/modules/zfs/manifests/init.pp
Ben Vincent 5ba483c68a feat: add ZFS facts to prevent zpool disk changes (#410)
- add zfs_zpools and zfs_datasets facts to detect existing ZFS resources
- skip zpool creation when pools already exist

Reviewed-on: #410
2025-10-18 21:24:33 +11:00

56 lines
1.7 KiB
Puppet

# Installs basic ZFS kernel and userland support.
#
# @example Declaring the class
# include zfs
#
# @example Tuning the ZFS ARC
# class { 'zfs':
# zfs_arc_max => to_bytes('256 M'),
# zfs_arc_min => to_bytes('128 M'),
# }
#
# @param conf_dir Top-level configuration directory, usually `/etc/zfs`.
# @param kmod_type Whether to use DKMS kernel packages or ones built to match
# the running kernel (only applies to RHEL platforms).
# @param manage_repo Whether to setup and manage external package repositories.
# @param package_name The name of the top-level metapackage that installs ZFS
# support.
# @param service_manage Whether to manage the various ZFS services.
# @param zfs_arc_max Maximum size of the ARC in bytes.
# @param zfs_arc_min Minimum size of the ARC in bytes.
class zfs (
Optional[Integer[0]] $zfs_arc_max,
Optional[Integer[0]] $zfs_arc_min,
Optional[Hash] $zpools,
Optional[Hash] $datasets,
Stdlib::Absolutepath $conf_dir = '/etc/zfs',
Enum['dkms', 'kabi'] $kmod_type = 'kabi',
Boolean $manage_repo = true,
Variant[String, Array[String, 1]] $package_name = 'zfs',
Boolean $service_manage = true,
) {
contain zfs::install
contain zfs::config
contain zfs::service
Class['zfs::install'] ~> Class['zfs::config'] ~> Class['zfs::service']
# create zpools
$zpools.each | $zpool, $data | {
# Only create zpool if it doesn't already exist
if $facts['zfs_zpools'] == undef or !($zpool in $facts['zfs_zpools']) {
zpool { $zpool:
* => $data
}
}
}
# create datasets
$datasets.each | $dataset, $data | {
zfs { $dataset:
* => $data
}
}
}