Ask Your Question

merge facts in hiera.yaml

asked 2015-11-11 15:57:14 -0600

masterdam79 gravatar image

updated 2015-11-11 15:57:51 -0600

Hey comm,

Setup puppet server

CentOS 7.1.1503

puppet 4.2.3

facter 3.1.1

hiera 3.0.4

Setup puppet agent

CentOS 7.1.1503

puppet 4.2.3

facter 3.1.1

hiera 3.0.4


I simply would like to merge facts in my hiera.yaml like the following.


So that I can make an array base_packages and have a specific package epel-release installed on CentOS 7 (but not on Debian 7 for example)

I'm trying to construct my hiera.yaml :hierarchy: with different variables from facter like: "os/%{::operatingsystem}%{::operatingsystemmajrelease}".

I tried the following in my hiera.yaml :hierarchy: to no avail:

  • "os/%{::operatingsystem}%{::operatingsystemmajrelease}" (file containing base_package array in /hieradata/os/CentOS7.yaml)
  • "os/%{::operatingsystem}-%{::operatingsystemmajrelease}" (file containing base_package array in /hieradata/os/CentOS-7.yaml)
  • "os/%{::operatingsystem}%/{::operatingsystemmajrelease}" (file containing base_package array in /hieradata/os/CentOS/7.yaml)

It only works if my hiera.yaml :hierarchy: contains:

  • "os/%{::operatingsystem}" (file containing base_package array in /hieradata/os/CentOS.yaml)


  • "os/%{::operatingsystemmajrelease}" (file containing base_package array in /hieradata/os/7.yaml)

This would result in the package epel-release being installed (or at least trying to and failing) on Debian 7 as well.


I've got a notify in my packages class to show me which packages would be installed by the agent.

Any idea why merging variables don't seem to work in hiera.yaml?

It seems that merging facts in hiera.yaml should work as intended but I'm not getting it to work.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-11-11 16:36:07 -0600

GregLarkin gravatar image

Hmm, that should work the way you want it to, and I've done it many times. To debug this, try using the hiera command line tool on your Puppet master.

Set up your hiera.yaml as you want it to be, and also put all of your data files in place. Then run the following commands on the Puppet master and post the output for each one.

hiera -d -c /path/to/hiera.yaml base_package ::operatingsystem=CentOS ::operatingsystemmajrelease=7

hiera -d -c /path/to/hiera.yaml base_package ::operatingsystem=Debian ::operatingsystemmajrelease=7

Invoking the hiera command with the -d option will print out all of the lookups that the tool tries while it looks for the base_package key. If you post the output back here, it should help to troubleshoot the problem.

edit flag offensive delete link more


Hey GregLarkin, thanks for your directions, got the following output: It seems that my %{environment} or %{::environment} variable not getting parsed..

masterdam79 gravatar imagemasterdam79 ( 2015-11-12 02:40:57 -0600 )edit

Here is my hiera.yaml: where in this case the ${::environment} variable is a top scope var

masterdam79 gravatar imagemasterdam79 ( 2015-11-12 02:45:42 -0600 )edit

When using the hiera command-line tool, you also have to explicitly set the environment if your hiera.yaml uses it. I forgot to mention that. So add "::environment=production" to the command line and send a link to that output.

GregLarkin gravatar imageGregLarkin ( 2015-11-12 17:59:42 -0600 )edit

Also, change your hiera.yaml to the form that you reported does not work and send a link to that output, too.

GregLarkin gravatar imageGregLarkin ( 2015-11-12 18:01:07 -0600 )edit

All problems are solved by upgrading to: puppet 4.3.2 facter 3.1.4 hiera 3.0.6

masterdam79 gravatar imagemasterdam79 ( 2016-03-02 16:09:29 -0600 )edit

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-11 15:57:14 -0600

Seen: 482 times

Last updated: Nov 11 '15