Ask Your Question
1

Use Hiera data directory structure as part of hierarchy?

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

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
    - 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?

Many thanks in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

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

ramindk gravatar image

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

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.

edit flag offensive delete link more
0

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

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

Stats

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

Seen: 353 times

Last updated: Nov 23 '15