From 0b60a31cc9cb5c62b23940d7e8f0fe104b4ce804 Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Wed, 24 Dec 2025 21:30:19 +1100 Subject: [PATCH] chore: testing a simple data_hash hiera plugin testing testing .... --- hiera.yaml | 2 ++ .../functions/custom_hiera_plugin/data_hash.rb | 16 ++++++++++++++++ site/profiles/manifests/base.pp | 9 +++++++++ 3 files changed, 27 insertions(+) create mode 100644 modules/custom_hiera_plugin/lib/puppet/functions/custom_hiera_plugin/data_hash.rb diff --git a/hiera.yaml b/hiera.yaml index d46d2ee..7a1132e 100644 --- a/hiera.yaml +++ b/hiera.yaml @@ -4,6 +4,8 @@ defaults: datadir: "hieradata" data_hash: "yaml_data" hierarchy: + - name: Custom Hiera Plugin + data_hash: custom_hiera_plugin::data_hash - name: Consolidated Data paths: - "nodes/%{trusted.certname}.yaml" diff --git a/modules/custom_hiera_plugin/lib/puppet/functions/custom_hiera_plugin/data_hash.rb b/modules/custom_hiera_plugin/lib/puppet/functions/custom_hiera_plugin/data_hash.rb new file mode 100644 index 0000000..20200f5 --- /dev/null +++ b/modules/custom_hiera_plugin/lib/puppet/functions/custom_hiera_plugin/data_hash.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'socket' + +# Custom Hiera Plugin +# This plugin returns static data for testing purposes +Puppet::Functions.create_function(:'custom_hiera_plugin::data_hash') do + # :reek:UtilityFunction + def data_hash(_options, _context) + # Return a simple hash with the required key-value pairs + { + 'custom_hiera_plugin::var1' => 'foo', + 'custom_hiera_plugin::hostname' => Socket.gethostname + } + end +end diff --git a/site/profiles/manifests/base.pp b/site/profiles/manifests/base.pp index f9d2f80..87f928b 100644 --- a/site/profiles/manifests/base.pp +++ b/site/profiles/manifests/base.pp @@ -1,6 +1,15 @@ # this is the base class, which will be used by all servers class profiles::base () { + # Test custom hiera plugin + notify { 'custom_hiera_plugin_test': + message => "Custom hiera plugin value: ${lookup('custom_hiera_plugin::var1')}", + } + + notify { 'custom_hiera_plugin_hostname': + message => "Custom hiera plugin hostname: ${lookup('custom_hiera_plugin::hostname')}", + } + # run a limited set of classes on the first run aimed at bootstrapping the new node if $facts['firstrun'] { include profiles::firstrun::init