feat: add ceph service management profiles and facts (#459)
## Summary
- Adds `Unkin::Ceph::Utils` facter module detecting ceph service instances via `systemctl list-units`, exposing `is_ceph_mon`, `is_ceph_mgr`, `is_ceph_mds`, `is_ceph_osd` booleans and a `ceph_services` hash of unit names
- Adds `profiles::ceph::mon`, `mgr`, `mds`, `osd` — each with `Boolean $ensure_running` that iterates discovered service instances and manages them as running and enabled
- Works across incus nodes (mon/mgr/mds/osd) and k8s compute/control nodes (osd only); verified on prodnxsr0001 which correctly reports `is_ceph_osd: true` and `ceph_services: {osd: [ceph-osd@5]}`
## Test plan
- [x] Noop deploy against prodnxsr0001.main.unkin.net passed cleanly
- [x] `ceph_services` fact returns correct service map
- [x] `is_ceph_osd` returns `True`, `is_ceph_mon` returns `False` as expected
- [x] Test on an incus/ceph node with mon/mgr/mds services
Reviewed-on: #459
This commit was merged in pull request #459.
This commit is contained in:
@@ -5,6 +5,10 @@ hiera_include:
|
|||||||
- incus
|
- incus
|
||||||
- zfs
|
- zfs
|
||||||
- profiles::ceph::node
|
- profiles::ceph::node
|
||||||
|
- profiles::ceph::mon
|
||||||
|
- profiles::ceph::mgr
|
||||||
|
- profiles::ceph::mds
|
||||||
|
- profiles::ceph::osd
|
||||||
- profiles::ceph::client
|
- profiles::ceph::client
|
||||||
- profiles::ceph::dashboard
|
- profiles::ceph::dashboard
|
||||||
- profiles::storage::cephfsvols
|
- profiles::storage::cephfsvols
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
hiera_include:
|
hiera_include:
|
||||||
- profiles::selinux::setenforce
|
- profiles::selinux::setenforce
|
||||||
- profiles::ceph::node
|
- profiles::ceph::node
|
||||||
|
- profiles::ceph::osd
|
||||||
- profiles::ceph::client
|
- profiles::ceph::client
|
||||||
- exporters::frr_exporter
|
- exporters::frr_exporter
|
||||||
- frrouting
|
- frrouting
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'facter'
|
||||||
|
|
||||||
|
# Detects active ceph service instances via systemctl and exposes facts
|
||||||
|
# for use in ceph service management profiles.
|
||||||
|
# rubocop:disable Style/ClassAndModuleChildren
|
||||||
|
module Unkin
|
||||||
|
module Ceph
|
||||||
|
# Detects active ceph service instances via systemctl and exposes Facter facts.
|
||||||
|
module Utils
|
||||||
|
TYPES = %w[mon mgr mds osd].freeze
|
||||||
|
|
||||||
|
def self.services
|
||||||
|
output = Facter::Core::Execution.execute(
|
||||||
|
'systemctl list-units "ceph*" --no-legend --plain --all 2>/dev/null',
|
||||||
|
on_fail: ''
|
||||||
|
)
|
||||||
|
parse_units(output)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.parse_units(output)
|
||||||
|
result = TYPES.each_with_object({}) { |type, hash| hash[type] = [] }
|
||||||
|
output.each_line do |line|
|
||||||
|
unit = line.split.first
|
||||||
|
next unless unit
|
||||||
|
|
||||||
|
match_unit(result, unit)
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.match_unit(result, unit)
|
||||||
|
TYPES.each do |type|
|
||||||
|
match = unit.match(/\Aceph-#{type}@(.+)\.service\z/)
|
||||||
|
result[type] << "ceph-#{type}@#{match[1]}" if match
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
TYPES.each do |type|
|
||||||
|
define_singleton_method(:"#{type}?") { !services[type].empty? }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# rubocop:enable Style/ClassAndModuleChildren
|
||||||
|
|
||||||
|
Facter.add('ceph_services') do
|
||||||
|
setcode { Unkin::Ceph::Utils.services }
|
||||||
|
end
|
||||||
|
|
||||||
|
Unkin::Ceph::Utils::TYPES.each do |type|
|
||||||
|
Facter.add("is_ceph_#{type}") do
|
||||||
|
setcode { Unkin::Ceph::Utils.public_send(:"#{type}?") }
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class profiles::ceph::mds (
|
||||||
|
Boolean $ensure_running = true,
|
||||||
|
) {
|
||||||
|
|
||||||
|
if $ensure_running and $facts['is_ceph_mds'] {
|
||||||
|
$facts['ceph_services']['mds'].each |String $svc| {
|
||||||
|
service { $svc:
|
||||||
|
ensure => running,
|
||||||
|
enable => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class profiles::ceph::mgr (
|
||||||
|
Boolean $ensure_running = true,
|
||||||
|
) {
|
||||||
|
|
||||||
|
if $ensure_running and $facts['is_ceph_mgr'] {
|
||||||
|
$facts['ceph_services']['mgr'].each |String $svc| {
|
||||||
|
service { $svc:
|
||||||
|
ensure => running,
|
||||||
|
enable => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class profiles::ceph::mon (
|
||||||
|
Boolean $ensure_running = true,
|
||||||
|
) {
|
||||||
|
|
||||||
|
if $ensure_running and $facts['is_ceph_mon'] {
|
||||||
|
$facts['ceph_services']['mon'].each |String $svc| {
|
||||||
|
service { $svc:
|
||||||
|
ensure => running,
|
||||||
|
enable => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class profiles::ceph::osd (
|
||||||
|
Boolean $ensure_running = true,
|
||||||
|
) {
|
||||||
|
|
||||||
|
if $ensure_running and $facts['is_ceph_osd'] {
|
||||||
|
$facts['ceph_services']['osd'].each |String $svc| {
|
||||||
|
service { $svc:
|
||||||
|
ensure => running,
|
||||||
|
enable => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user