From 576f607931e69c8e0c63ec420b622a40e2514780 Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Mon, 22 Nov 2021 17:08:47 +0100 Subject: [PATCH] use hiera for service class osfamily if statements this should give some more flexibility in the future. --- data/Debian-family.yaml | 5 +++++ data/OpenBSD-family.yaml | 5 +++++ data/common.yaml | 3 +++ hiera.yaml | 3 +++ manifests/service.pp | 35 +++++++++++------------------------ 5 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 data/Debian-family.yaml create mode 100644 data/OpenBSD-family.yaml diff --git a/data/Debian-family.yaml b/data/Debian-family.yaml new file mode 100644 index 0000000..8749028 --- /dev/null +++ b/data/Debian-family.yaml @@ -0,0 +1,5 @@ +--- +# Defaults for Debian os family (eg. Debian, Ubuntu etc) + +prosody::service::hasstatus: ~ +prosody::service::restart: ~ diff --git a/data/OpenBSD-family.yaml b/data/OpenBSD-family.yaml new file mode 100644 index 0000000..b91792d --- /dev/null +++ b/data/OpenBSD-family.yaml @@ -0,0 +1,5 @@ +--- +# Defaults for OpenBSD os family + +prosody::service::hasstatus: ~ +prosody::service::restart: ~ diff --git a/data/common.yaml b/data/common.yaml index 331cd14..ff591d4 100644 --- a/data/common.yaml +++ b/data/common.yaml @@ -65,3 +65,6 @@ prosody::community_modules::ensure: present prosody::community_modules::path: /var/lib/prosody/modules prosody::community_modules::source: https://hg.prosody.im/prosody-modules/ prosody::community_modules::type: hg + +prosody::service::hasstatus: false +prosody::service::restart: '/usr/bin/prosodyctl reload' diff --git a/hiera.yaml b/hiera.yaml index 5555192..ed0b226 100644 --- a/hiera.yaml +++ b/hiera.yaml @@ -7,5 +7,8 @@ hierarchy: - name: "osname" paths: - "os/%{facts.os.name}.yaml" + - name: "osfamily" + paths: + - "%{facts.os.family}-family.yaml" - name: common path: common.yaml diff --git a/manifests/service.pp b/manifests/service.pp index ec891ff..db98417 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,29 +1,16 @@ # == Class: prosody::service -class prosody::service { +class prosody::service( + Optional[Boolean] $hasstatus = undef, + Optional[String] $restart = undef, +) { + if $prosody::daemonize { - case $facts['os']['family'] { - 'OpenBSD': { - service { 'prosody': - ensure => running, - enable => true, - require => Class[prosody::config], - } - } - 'Debian': { - service { 'prosody': - ensure => running, - enable => true, - require => Class[prosody::config], - } - } - default: { - service { 'prosody' : - ensure => running, - hasstatus => false, - restart => '/usr/bin/prosodyctl reload', - require => Class[prosody::config], - } - } + service { 'prosody': + ensure => running, + enable => true, + hasstatus => $hasstatus, + restart => $restart, + require => Class[prosody::config], } } }