# Use Hiera data directory structure as part of hierarchy?

I'm trying to find out if it's possible to use the directory structure of the Hiera data directory as part of the hierarchy itself. Here's an example of the directory structure I have in mind to illustrate this:

- client_a
- client_common.yaml
- project_1
- project_common.yaml
- web1.example1.com
- web2.example1.com
- db.example1.com
- project_2
- project_common.yaml
- web.example2.com
- db.example2.com
- client_b
- client_common.yaml
- project_3
- project_common.yaml
- web.example3.com
- db.example3.com


In this structure, the client_common.yaml files in each "client" directory would contain some client-specific data which I'd like to be inherited by all the projects, and subsequently the nodes, under that client.

At the next level down, the project_common.yaml files under each "project" directory would contain project-specific data, common to all the nodes under that project.

Finally, the nodes themselves (e.g. web1.example1.com under project_1) would be matched by hostname in the usual Hiera way.

In essence I'm trying to use the directory structure itself as part of the hierarchy. In the Hiera configuration where the hierarchy is defined, I think this could be achieved by using wildcards (hypothetically - I know wildcards aren't allowed here). The names of the client and project directories would not come from facts and would be irrelevant to Hiera - they would be used purely to maintain a hierarchical structure. Here's a (hypothetical!) example of what I'd like to achieve:

:hierarchy:
- "*/*/%{::hostname}"
- "*/*/project_common.yaml"
- "*/client_common.yaml"
- common


I've used wildcards to represent the client -> project directory structure, but the names of those directories themselves would not matter; they're simply 'placeholders' to maintain the structure.

Does this approach make sense? Is it possible to implement in this way, or a similar way? Or is there another, better way of implementing what I'm trying to achieve?

edit retag close merge delete

Sort by » oldest newest most voted

You can use the dir structure, but it needs to line up to facts.

:hierarchy:
- "%{my_client}/%{my_project}/%{::hostname}"
- "%{my_client}/%{my_project}/project_common.yaml"
- "%{my_client}/client_common.yaml"
- common


You might use simple k/v facts in /etc/facter/facts.d/ to set my_client and my_project facts.

more

You need to give hiera the exact path to yaml/json files, you can't use wildcards.

From the documentation:

Must be a string or an array of strings, where each string is the name of a static or dynamic data source. (A dynamic source is simply one that contains a %{variable} interpolation token)

more