Ask Your Question

Is there a way to use array of values in looking up classes via Hiera ?

asked 2015-07-01 19:27:11 -0600

Felix Lam gravatar image

Hi chaps,

I have implemented a few custom Facts to describe the hierarchy of role(s) of a server (E.g. Level 1 - Env Type : UAT,PROD,etc., Level 2 - Application Type, Level 3 - Application Component...etc) . The facts are stored in a text config file sitting on the target server. I have been trying to use Hiera to lookup the right puppet classes to be used for my servers based on the custom facts defined. One problem I have encountered is that for each custom fact, I can just have one single value. For example, at the Application Component fact, I cannot tell Hiera that this server is supposed to run Component A, B, C altogether, since Hiera yaml files does not seem to support an array of values. I can possibly use array[0], array[1].. etc in my hiera yaml files to get around the problem, but that means I have to pre-define a maximum number of different application components for each server. Is there any better way to implement Hiera to address my problem ?

Thanks a lot.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-07-02 09:03:10 -0600

If I understand you correctly, and I admit, I may not have, then you are hitting the following case:


Hiera can only interpolate variables whose values are strings. (Numbers from Puppet are also passed as strings and can be used safely.) You cannot interpolate variables whose values are booleans, numbers not from Puppet, arrays, hashes, resource references, or an explicit undef value.

Without more detail, it's difficult to give you a better answer. I can tell you that one way we got around this issue was to use PuppetDB Query (

This tool is quite nice as it allows us to do dynamic lookups , return arrays, and not hard-code a set of values, as would be required in this particular instance.

edit flag offensive delete link more

answered 2015-07-02 18:33:45 -0600

pizzaops gravatar image

Hiera definitely support arrays of values and arrays of values are the ONLY reasonable way to get classes out of hiera.

It's the very first Google result for "hiera classes":

If we click through, we see that the last section listed is "Assigning Classes to Nodes With Hiera (hiera_include)":

In that section:

3. Create classes keys throughout your Hiera hierarchy. The value of each classes key should be an array.

Look at that section for the complete example, including syntax. Lots of help out there for this kind of stuff if you Google :)

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-07-01 19:27:11 -0600

Seen: 432 times

Last updated: Jul 02 '15