Access the hiera area from a custom Puppet type

I am creating a custom type and I cannot access the hiera scope from the default block for

module Puppet require 'puppet/parser/functions/hiera' newtype(:my_type) do ensurable newparam(:myparam) do defaultto { Puppet::Parser::Functions.hiera('myparam') } end newproperty(:value) do desc "Value of the item." end end end 

But I get

 Error: undefined method `hiera' for Puppet::Parser::Functions:Module 

I am using Puppet 3.8 and the future parser

As a workaround, we use

  $my_vals = hiera_hash('mytype_vals') create_resource(my_type, $myvals, {myparam => hiera('myparam')}) 

This works fine, but it is expected that my_type objects will be created somewhere in the directory, it is expected that myparam will be the same in all instances. Therefore, multiple declaration of a default value is not required.

Another approach would be to post

 My_type{ myparam => hiera('myparam') } 

In the manifest node. This would also work, but we are developing a module, and the main manifest is beyond the scope of our work.

+7
puppet hiera
source share
1 answer

You cannot access the hiera data from the provider, because the provider starts the agent side and hiera starts the main side.

You mentioned that in your comments you are characterless, this has nothing to do with it, as there is also a β€œwizard” that compiles the Puppet directory and evaluates the values ​​of hiera and the β€œagent” that applies the directory using providers.

Imagine Puppet running as a sequence of steps:

  • Agent sends fact list to master
  • The wizard compiles the site manifest to find a list of classes to include node
  • The wizard evaluates all hiera parameters and variables.
  • The wizard compiles the modules into a directory
  • The wizard sends the directory to the agent
  • The agent applies the catalog by submitting parameters to suppliers.

So your best bet is to wrap the provider in a definition type. Use the define class to get the default values ​​of hiera and pass them to the provider, as well as enable default rewriting.

+2
source share

All Articles