Hiera hierarchy - read variable from class included in common

asked 2015-06-15 07:46:17 -0600

Tomasz Olszewski gravatar image

updated 2015-06-18 00:47:10 -0600


My problem is pretty simple. Here is hiera.yaml file content:

- "projects/%{::domain}/hieradata/%{::fqdn}"
- "projects/%{::domain}/hieradata/%{::hostname}"
- "projects/%{::domain}/hieradata/common"

In my puppet projects, I always try to include everything what is shared in common.yaml file, so I don't need to repeat myself using <fqdn>.yaml files.

Here is my problem:

  • I have class myclass::config where I defined variable $variable = 'test'
  • in common.yaml I included myclass::config
  • after few months I created class custom1, which requires argument $myclass::config::variable
  • class custom1 needs to be loaded only on test-1 server, so my first approach was to include it in test-1.yaml

What happened - variable $myclass::config::variable was empty, because common.yaml is evaluated AFTER my class custom1 is loaded.

My first though was to move common.yaml to first place in hierarchy, but as I read in documentation it's not the best idea, because hiera stops digging for variables after finding first occurence. I did it only for tests, and moving common file to the top of hiera hierarchy do the trick.

So I stuck. Can you suggest how to solve this issue? I understand why my issue occurs (order of loading classes), but how to deal with this situation?

  • Should I move all variables directly to hiera?
  • Or maybe include myclass::config on all servers, instead of common?
  • Alternatively I can move common to beginning of hierarchy
  • Or create another shared file in hiera hierarchy that will be included on beginning

I'll appreciate any good solutions :-)

edit retag flag offensive close merge delete


could you please post the output of the hiera lookup? hiera -d my::precious::variable . and how do lookup the var from the module, eg var => hiera('asdf')?

far4d gravatar imagefar4d ( 2015-06-15 07:53:41 -0600 )edit

far4d - I need to apologize. I simplified my example too much, and it was working as expected. I updated initial post, and tested once again if my issue is reproducable. Problem exists only when I try to use variable defined inside of a class, not in hiera.

Tomasz Olszewski gravatar imageTomasz Olszewski ( 2015-06-15 10:28:56 -0600 )edit