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