Merge pull request 'neoloc/cephfs' (#54) from neoloc/cephfs into develop

Reviewed-on: https://git.query.consul/unkinben/puppet-prod/pulls/54
This commit was merged in pull request #54.
This commit is contained in:
2024-06-23 15:34:04 +10:00
13 changed files with 186 additions and 2 deletions
+43
View File
@@ -0,0 +1,43 @@
# profiles::ceph::client
class profiles::ceph::client (
String $fsid,
Array[Stdlib::Host] $mons,
Stdlib::Absolutepath $config_file = '/etc/ceph/ceph.conf',
String $owner = 'ceph',
String $group = 'ceph',
Stdlib::Filemode $mode = '0644',
Hash $keyrings = {},
) {
# dont run this on proxmox nodes
if $facts['enc_role'] != 'roles::infra::proxmox::node' {
# install the ceph client package
package { 'ceph-common':
ensure => installed,
}
# manage the ceph directory
file { '/etc/ceph':
ensure => directory,
owner => $owner,
group => $group,
mode => $mode,
require => Package['ceph-common'],
}
# create a basic client config
file { $config_file:
ensure => file,
owner => $owner,
group => $group,
mode => $mode,
content => template('profiles/ceph/client.conf.erb'),
require => Package['ceph-common'],
}
# manage ceph keyrings
create_resources('profiles::ceph::keyring', $keyrings)
}
}
+21
View File
@@ -0,0 +1,21 @@
# profiles::ceph::keyring
define profiles::ceph::keyring (
String $key,
String $user = $name,
String $type = 'client',
Stdlib::Filemode $mode = '0600',
String $owner = 'ceph',
String $group = 'ceph',
Stdlib::Absolutepath $keyring_dir = '/etc/ceph',
) {
$keyring_file = "${keyring_dir}/ceph.${type}.${user}.keyring"
file { $keyring_file:
ensure => file,
owner => $owner,
group => $group,
mode => $mode,
content => Sensitive(template('profiles/ceph/keyring.erb')),
require => File[$keyring_dir],
}
}
+16
View File
@@ -0,0 +1,16 @@
# profiles::media::sonarr
class profiles::media::sonarr (
Stdlib::Absolutepath $media_root = '/shared/media',
) {
include profiles::ceph::client
# manage the sharedvol
profiles::storage::cephfsvol {"${::facts['networking']['fqdn']}_media":
mount => $media_root,
keyring => '/etc/ceph/ceph.client.media.keyring',
cephfs_name => 'media',
cephfs_fs => 'mediafs',
require => Profiles::Ceph::Keyring['media'],
}
}
@@ -0,0 +1,69 @@
# 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],
}
}
}
@@ -0,0 +1,3 @@
[global]
fsid = <%= @fsid %>
mon_host = <%= @mons.join(' ') %>
+1
View File
@@ -0,0 +1 @@
<%= @key %>
@@ -6,5 +6,6 @@ class roles::apps::media::sonarr {
}else{
include profiles::defaults
include profiles::base
include profiles::media::sonarr
}
}