Ask Your Question

Use Hiera data directory structure as part of hierarchy?

asked 2015-11-15 16:10:18 -0600

Rick Steckles gravatar image

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
  - project_2
    - project_common.yaml
- client_b
  - client_common.yaml
  - project_3
    - project_common.yaml

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. 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:

  - "*/*/%{::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?

Many thanks in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-11-22 15:04:47 -0600

ramindk gravatar image

updated 2015-11-23 10:15:01 -0600

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

  - "%{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.

edit flag offensive delete link more

answered 2015-11-16 08:27:07 -0600

Cristian Falcas gravatar image

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)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-11-15 16:10:18 -0600

Seen: 644 times

Last updated: Nov 23 '15