Ask Your Question
0

merge facts in hiera.yaml

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

masterdam79 gravatar image

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

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

Question

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

"/hieradata/os/CentOS7.yaml".

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)

or

  • "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.

Debugging

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
1

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

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

Comments

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

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

Here is my hiera.yaml: http://pastebin.com/9JdwqMiR where in this case the ${::environment} variable is a top scope var

masterdam79 gravatar imagemasterdam79 ( 2015-11-12 02:45:42 -0500 )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 -0500 )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 -0500 )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 -0500 )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

Stats

Asked: 2015-11-11 15:57:14 -0500

Seen: 259 times

Last updated: Nov 11 '15