puppet-prod/site/profiles/manifests/storage/cephfsvol.pp
Ben Vincent 5631f07e6e feat: add cephfs shared volume define
- add ceph class to manage ceph client configuration/packages
- add cephfs define for mounting volumes
- add ceph keyring define to manage secrets used to mount cephfs
2024-06-23 15:33:33 +10:00

70 lines
1.9 KiB
Puppet

# profiles::storage::cephfsvol
define profiles::storage::cephfsvol (
Enum['present', 'absent', 'mounted'] $ensure = 'mounted',
String $owner = 'root',
String $group = 'root',
Stdlib::Filemode $mode = '0755',
Stdlib::Absolutepath $mount = '/shared',
Array[Enum[
'defaults', 'ro', 'rw', 'sync', 'async',
'noatime', 'nodiratime', 'noexec', 'nosuid',
'nodev', 'remount', 'auto', 'noauto'
]] $mount_options = ['noatime', 'nodiratime'],
Variant[Stdlib::Host, Array[Stdlib::Host]] $cephfs_mon = 'ceph-mon.service.consul',
Stdlib::Absolutepath $cephfs_path = '/',
String $cephfs_name = 'admin',
String $cephfs_fs = 'cephfs',
Optional[Stdlib::Absolutepath] $keyring = undef,
) {
# mkdir -p $mount_path
mkdir::p {$mount: }
# ensure the mount path exists
file { $mount:
ensure => directory,
owner => $owner,
group => $group,
mode => $mode,
require => [
Mkdir::P[$mount],
Package['ceph-common']
],
}
# join options into a comma seperated list
$options = join($mount_options, ',')
# if a ceph keyring is required, it will be added here
if $keyring {
$mount_options_string = "${options},fs=${cephfs_fs},name=${cephfs_name},secretfile=${keyring}"
} else {
$mount_options_string = "${options},fs=${cephfs_fs},name=${cephfs_name}"
}
# convert cephfs_servers (monitors) into a list
$mon_addresses = $cephfs_mon ? {
Array => join($cephfs_mon, ','),
default => $cephfs_mon,
}
# manage the mount
mount { $mount:
ensure => $ensure,
atboot => true,
device => "${mon_addresses}:${cephfs_path}",
fstype => 'ceph',
options => $mount_options_string,
require => File[$mount],
}
# unmount when the mount should be removed
if $ensure == 'absent' {
exec { "umount_${mount}":
command => "umount ${mount}",
onlyif => "mount | grep ${mount}",
before => Mount[$mount],
}
}
}