I'm building a custom type and I'm unable to get access to the hiera scope from a defaultto block
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'm actually using Puppet 3.8 and future parser
As a workaround, we use
$my_vals = hiera_hash('mytype_vals')
create_resource(my_type, $myvals, {myparam => hiera('myparam')})
That works fine, but my_type
objects are expected to be instantiated anywhere in the catalog, an myparam
is expected to be the same across all instances. So multiple default value declaration should not be necessary.
Another approach would be to place
My_type{
myparam => hiera('myparam')
}
In the node manifest. That would do the trick, too, but we are developing a module, and main manifest is out of our scope
You can't access hiera data from a provider, because a provider runs agent side and hiera runs master side.
You've mentioned you run masterless in your comments, this is irrelevant as there is still a "master" run which compiles the Puppet catalog and evaluates hiera values and an "agent" run that applies the catalog using providers.
Imagine the Puppet run as a series of steps:
So your best bet is to wrap the provider in a define type. Use the define class to get hiera defaults and pass them to the provider, while allowing the default to be overwritten.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With