hiera key questions, key naming and per-file keys

20 views
Skip to first unread message

Christopher Wood

unread,
Mar 1, 2018, 10:04:04 AM3/1/18
to puppet...@googlegroups.com
As background, for "reasons" I am looking at individual domains in hiera as keys. I do have questions beyond "why would I even".

A) hiera lookup key format

I notice that if I use puppet lookup to test things I get similar behaviour as using lookup() from a manifest, a key with dots in it is truncated. Notice how the node hierarchy understand the key as "www" below(1). I could just use underscores but I'd rather understand what was going on first.

Is there a list of permitted characters in a hiera key lookup?

B) hierarchy interpolation

https://puppet.com/docs/puppet/5.4/hiera_intro.html#hierarchies-interpolate-variables

Is there anything else a hierarchy can interpolate? I'm thinking it would be easier to explain to people that 'www.boitc.test' information was listed under hieradata/domains/www.boitc.test.yaml rather than in the longer hieradata/domains.yaml.

Failing that, is it future-proof to use $title in a hierarchy in the same manner as $classname seems sometimes used?


(1) The lookup that is misunderstood in the environment data provider.

puppet lookup --node host.domain.com -d 'www.boitc.test'

Searching for "www.boitc.test"
Global Data Provider (hiera configuration version 5)
No such key: "www.boitc.test"
Environment Data Provider (hiera configuration version 5)
Using configuration "/etc/puppetlabs/code/environments/puppetmasters_tls/hiera.yaml"
Hierarchy entry "nodes"
Path "/etc/puppetlabs/code/environments/puppetmasters_tls/hieradata/nodes/host.domain.com.eyaml"
Original path: "nodes/%{::trusted.certname}.eyaml"
No such key: "www"


Henrik Lindberg

unread,
Mar 1, 2018, 5:37:08 PM3/1/18
to puppet...@googlegroups.com
On 01/03/18 16:03, Christopher Wood wrote:
> As background, for "reasons" I am looking at individual domains in hiera as keys. I do have questions beyond "why would I even".
>
> A) hiera lookup key format
>
> I notice that if I use puppet lookup to test things I get similar behaviour as using lookup() from a manifest, a key with dots in it is truncated. Notice how the node hierarchy understand the key as "www" below(1). I could just use underscores but I'd rather understand what was going on first.
>

A '.' is an operator that "digs" into a data structure. If you are
looking up the key "foo", and it results in a hash, and this hash has a
key "bar", you can get its value by looking up "foo.bar".

You can quote the period to make it a verbatim period char. For example
by looking up "'foo.bar'", or "foo'.'bar" would lookup the entire key
including the period.

The '%' char has special meaning.

> Is there a list of permitted characters in a hiera key lookup?
>
You should read up on the hiera documentation to get all the details.
It is on puppet's documentation site.

> B) hierarchy interpolation
>
> https://puppet.com/docs/puppet/5.4/hiera_intro.html#hierarchies-interpolate-variables
>
> Is there anything else a hierarchy can interpolate? I'm thinking it would be easier to explain to people that 'www.boitc.test' information was listed under hieradata/domains/www.boitc.test.yaml rather than in the longer hieradata/domains.yaml.
>
> Failing that, is it future-proof to use $title in a hierarchy in the same manner as $classname seems sometimes used?
>

That is not a good design, it makes keys have different value depending
from where they are looked up. In addition it forces hiera to have to
evict the caches so it is bad for performance as well.

Only use top scope variables (for example facts) in your hierarchy.

>
> (1) The lookup that is misunderstood in the environment data provider.
>
> puppet lookup --node host.domain.com -d 'www.boitc.test'
>

quote the '.' to make it work

> Searching for "www.boitc.test"
> Global Data Provider (hiera configuration version 5)
> No such key: "www.boitc.test"
> Environment Data Provider (hiera configuration version 5)
> Using configuration "/etc/puppetlabs/code/environments/puppetmasters_tls/hiera.yaml"
> Hierarchy entry "nodes"
> Path "/etc/puppetlabs/code/environments/puppetmasters_tls/hieradata/nodes/host.domain.com.eyaml"
> Original path: "nodes/%{::trusted.certname}.eyaml"
> No such key: "www"
>
>

- henrik
--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Christopher Wood

unread,
Mar 2, 2018, 8:11:59 AM3/2/18
to puppet...@googlegroups.com
(inline)

On Thu, Mar 01, 2018 at 11:36:40PM +0100, Henrik Lindberg wrote:
> On 01/03/18 16:03, Christopher Wood wrote:
> > As background, for "reasons" I am looking at individual domains in hiera as keys. I do have questions beyond "why would I even".
> >
> > A) hiera lookup key format
> >
> > I notice that if I use puppet lookup to test things I get similar behaviour as using lookup() from a manifest, a key with dots in it is truncated. Notice how the node hierarchy understand the key as "www" below(1). I could just use underscores but I'd rather understand what was going on first.
> >
>
> A '.' is an operator that "digs" into a data structure. If you are looking
> up the key "foo", and it results in a hash, and this hash has a key "bar",
> you can get its value by looking up "foo.bar".
>
> You can quote the period to make it a verbatim period char. For example by
> looking up "'foo.bar'", or "foo'.'bar" would lookup the entire key including
> the period.
>
> The '%' char has special meaning.
>
> > Is there a list of permitted characters in a hiera key lookup?
> >
> You should read up on the hiera documentation to get all the details.
> It is on puppet's documentation site.

Yes it's all right there in front of me. *facepalm*

For posterity, I had missed this bit:

https://puppet.com/docs/puppet/5.4/hiera_automatic.html#access-hash-and-array-elements-using-a-keysubkey-notation

> > B) hierarchy interpolation
> >
> > https://puppet.com/docs/puppet/5.4/hiera_intro.html#hierarchies-interpolate-variables
> >
> > Is there anything else a hierarchy can interpolate? I'm thinking it would be easier to explain to people that 'www.boitc.test' information was listed under hieradata/domains/www.boitc.test.yaml rather than in the longer hieradata/domains.yaml.
> >
> > Failing that, is it future-proof to use $title in a hierarchy in the same manner as $classname seems sometimes used?
> >
>
> That is not a good design, it makes keys have different value depending from
> where they are looked up. In addition it forces hiera to have to evict the
> caches so it is bad for performance as well.

I had not realized that, it's obvious with a night's sleep now.

> Only use top scope variables (for example facts) in your hierarchy.
>
> >
> > (1) The lookup that is misunderstood in the environment data provider.
> >
> > puppet lookup --node host.domain.com -d 'www.boitc.test'
> >
>
> quote the '.' to make it work
>
> > Searching for "www.boitc.test"
> > Global Data Provider (hiera configuration version 5)
> > No such key: "www.boitc.test"
> > Environment Data Provider (hiera configuration version 5)
> > Using configuration "/etc/puppetlabs/code/environments/puppetmasters_tls/hiera.yaml"
> > Hierarchy entry "nodes"
> > Path "/etc/puppetlabs/code/environments/puppetmasters_tls/hieradata/nodes/host.domain.com.eyaml"
> > Original path: "nodes/%{::trusted.certname}.eyaml"
> > No such key: "www"
> >
> >
>
> - henrik
> --
>
> Visit my Blog "Puppet on the Edge"
> http://puppet-on-the-edge.blogspot.se/
>
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/p79v5p%248oe%241%40blaine.gmane.org.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages