diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-19 00:59:23 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-10-19 00:59:23 +0200 |
commit | 7d20a1e6a1d66d9611d197d777bd1aa9082269c0 (patch) | |
tree | 2691f0488695d34edd0ffb173c3857aa7c3daeeb | |
parent | Initial commit. (diff) | |
download | periodic-7d20a1e6a1d66d9611d197d777bd1aa9082269c0.tar.gz periodic-7d20a1e6a1d66d9611d197d777bd1aa9082269c0.tar.xz |
Initial add.
-rw-r--r-- | manifests/init.pp | 38 | ||||
-rw-r--r-- | manifests/setup.pp | 32 | ||||
-rw-r--r-- | metadata.json | 37 | ||||
-rw-r--r-- | pdk.yaml | 2 | ||||
-rw-r--r-- | templates/periodic-entry | 6 |
5 files changed, 115 insertions, 0 deletions
diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..313c1fd --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,38 @@ +# @summary Enable a pre-existing periodic rule +# @param value +# Target value for parameter. +# Strings will be double quoted, meaning that shell expansions will +# be done in them at the time of use. Integers will be interpreted +# inserted literally. +# +# This is most often set to "YES" or "NO" +# +# @param key +# The actually name to set. Valid values depen on available +# periodic files. +# @param ensure +# Should the resource be added or removed. +# Note that if `periodic::setup::purge` is true then simply removing +# the puppet declaratipurges the rule. +define periodic ( + Variant[String, Integer] $value, + String $key = $name, + Enum['present', 'absent'] $ensure = 'present', +) { + include periodic::setup + + $file = "${periodic::setup::periodic_dir}/${key}${periodic::setup::suffix}" + + $value_ = $value ? { + Integer => $value, + String => "\"${value}\"", + } + + file { $file: + ensure => $ensure, + contents => epp("${module_name}/periodic-entry", { + key => $key, + value => $value_ + }), + } +} diff --git a/manifests/setup.pp b/manifests/setup.pp new file mode 100644 index 0000000..4715fb6 --- /dev/null +++ b/manifests/setup.pp @@ -0,0 +1,32 @@ +# @summary Prepare for periodic rules to be loaded. +# +# @param periodic_dir +# Directory in which periodic rules should be kept +# @param purge +# Should the periodic directory be purged. +# This means that unreferenced files will be deleted. +# @param suffix +# Suffix of all "active" files in the periodic dir. +# @param ensure +# Should the periodic dir be enabled. +class periodic::setup ( + Stdlib::Path $periodic_dir = '/usr/local/etc/periodic.conf.d', + Boolean $purge = true, + String $suffix = '.periodic', + Enum['present', 'absent'] $ensure = 'present', +) { + $content = @("EOF"/$) + periodic_conf_files="${periodic_dir}/*${suffix} \${periodic_conf_files}" + | EOF + + file_line { 'Periodic - Enable sourcing of files in directory': + ensure => $ensure, + path => '/etc/periodic.conf', + line => $content, + } + + file { $periodic_dir: + ensure => if $ensure == 'present' { 'directory' } else { 'absent' }, + purge => $purge, + } +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..20a8e79 --- /dev/null +++ b/metadata.json @@ -0,0 +1,37 @@ +{ + "name": "HugoNikanor-periodic", + "version": "0.1.0", + "author": "HugoNikanor", + "summary": "Manage FreeBSD's periodic timers", + "license": "Apache-2.0", + "source": "https://git.hornquist.se/puppet/periodic", + "operatingsystem_support": [ + { + "operatingsystem": "FreeBSD", + "operatingsystemrelease": [ + "13.2" + ] + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": ">= 6.21.0 < 8.0.0" + } + ], + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">= 4.13.1 < 9.0.0" + }, + { + "name": "puppetlabs/concat", + "version_requirement": ">= 7.0.0 < 8.8.8" + } + ], + "tags": [ + ], + "pdk-version": "2.5.0", + "template-url": "pdk-default#2.5.0", + "template-ref": "tags/2.5.0-0-g369d483" +} diff --git a/pdk.yaml b/pdk.yaml new file mode 100644 index 0000000..4bef4bd --- /dev/null +++ b/pdk.yaml @@ -0,0 +1,2 @@ +--- +ignore: [] diff --git a/templates/periodic-entry b/templates/periodic-entry new file mode 100644 index 0000000..6dac308 --- /dev/null +++ b/templates/periodic-entry @@ -0,0 +1,6 @@ +<%- | String $key, + String $value, + | -%> +# File managed by Puppet. +# Local changes WILL be overwritten +<%= $key %>=<%= $value %> |