Im trying to use heira to override class parameters in puppet. I have this class:
class test(
$parameter1="codeddefault"
)
{
notify {"parameter1 is $parameter1": }
}
This is my hiera.yaml:
---
version: 5
defaults:
# The default value for "datadir" is "data" under the same directory as the hiera.yaml
# file (this file)
# When specifying a datadir, make sure the directory exists.
# See https://docs.puppet.com/puppet/latest/environments.html for further details on environments.
# datadir: data
# data_hash: yaml_data
hierarchy:
- name: "Per-node data (yaml version)"
path: "nodes/%{::trusted.certname}.yaml"
- name: "Group (Server class or function. e.g. lg for logging server)"
path: "groups/%{facts.group}.yaml"
- name: "Other YAML hierarchy levels"
paths:
- "common.yaml"
The fact that defines "groups" goes off a substring of the hostname, according to some internal naming convention. What that convention is, is unimportant for the purposes of this question. Needless to say I have checked it works as expected, as later output will show.
Lets assume for the purposes of this question that the group in this case, is "inlg" My expectation is that I should be able to put the following in "inlg.yaml":
test::parameter1: groupvalue.
And when I run my manifest (which includes the test class) that the notify resource should output:
parameter1 is groupvalue
However this is not the case. It instead, returns "codeddefault"
To test the problem further, I set the following values in "{::trusted.certname}.yaml"
testvalue: host
and this in inlg.yaml:
testvalue: group
I add this to the class:
$testvalue = lookup("testvalue")
notify {"testvalue is $testvalue": }
Predictably, the code returns that testvalue equals "host". This makes sense to me as the value in the more specific "{::trusted.certname}.yaml" is overriding the value in inlg.yaml (albeit a "normal" lookup and not a class parameter)
If I then remove
testvalue: host
from "{::trusted.certname}.yaml"
testvalue then equals "group"
Which, again, is what I would expect.
To confuse things further, If I set this in {::trusted.certname}.yaml:
test::parameter1: blah
Then the notify resource in the class shown above, returns "blah"
If I remove
test::parameter1: blah
from {::trusted.certname}.yaml, the value of parameter1 once again returns to "codeddefault"
Im expecting it to pick up the value from the "group" yaml file (inlg.yaml) as the "normal" lookups do.
What am I missing?
Thanks in advance.