0

I have added in my hiera.yaml an hierarchy like this

- "nodes/%{::certname}"
- "locations/{::location}.yaml"
- "groups/%{::group}.yaml"
- common

For the nodes it I know hiera looks them up through the nodes resource. But how does it work for locations or groups? Do I need to create a custom fact? And if yes how can i assign the node that fact. Can I do that in the node definition in the site.pp like this:

 node example.com{
    ::location = "new york"
    ::group = "mailer"  ... }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

For the nodes it I know hiera looks them up through the nodes resource.

I'm not positive that I understand what you mean, but I think you have a misunderstanding.

But how does it work for locations or groups?

Hiera interpolation inserts the values of Puppet variables and / or the results of certain interpolation functions. certname, location, and group are the same in that respect, but the certname variable is provided automatically by Puppet, based on the certificate presented by the agent to identify itself. (That is wholly orthogonal to node blocks and node termini, though they, too, use the certname.)

Do I need to create a custom fact?

You can do it that way, because all facts presented by the agent are available as top-scope Puppet variables. The variables interpolated by Hiera do not need to be derived from facts, but they do need to be defined before Hiera lookups that require them are performed, and facts are available to the catalog builder from before it starts evaluating the site manifest.

And if yes how can i assign the node that fact.

That's entirely a question of how you implement the fact.

Can I do that in the node definition in the site.pp[?]

You cannot set facts in your node blocks, but you can set node-scope and top-scope variables, and these should then be available to Hiera for interpolation. For node scope, the syntax looks like this:

node example.com{
  $location = "new york"
  $group = "mailer"
  # ...
}

For top scope it's the same, just outside the node block. Alternatively, you can define top-scope variables (among other things) via an external node classifier.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157