Ask Your Question

hiera lookups are not performing as expected

asked 2013-04-02 11:37:44 -0500

bothra gravatar image

updated 2013-04-02 12:30:30 -0500

ramindk gravatar image

We are using puppet 2.7.21 and in effort to move to 3.x I am moving our lookups from extlookup to hiera. We have one puppet master and only around 25 nodes being managed.


- yaml

:datadir: /etc/puppet/hieradata

  - %{fqdn}
  - %{domain}
  - common

  - puppet

inside /etc/puppet/hieradata:

- common.yaml

in common.yaml we have use_nagios: true

some hostnames have use_nagios: false defined

in class::ssh:

  if hiera("use_nagios ...
edit retag flag offensive close merge delete



What happens if you try $yes_nagios = hiera('use_nagios') and then built the if statement as if $yes_nagios == 'true' { and so for. You might also try a notify statement to see ...(more)

ramindk gravatar imageramindk ( 2013-04-02 12:36:54 -0500 )edit

thanks ramindk, this was very helpful. declaring the variable outside of the if statement seems to be the proper way of doing hiera lookups.

bothra gravatar imagebothra ( 2013-04-02 13:53:45 -0500 )edit

Instead of closing this, you should have written the comment up as an answer, and marked it as correct.

Ancillas gravatar imageAncillas ( 2013-04-02 17:57:41 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2013-04-03 12:50:10 -0500

bothra gravatar image

updated 2013-04-03 15:53:11 -0500

following Ancillas advice...

I was able to achieve expected results by changing class::ssh to

$nagios_var = hiera('use_nagios')

if $nagios_var == 'true' {
 @@nagios_service { "check_ssh_${hostname}":
   ensure    => present,
   use       => "check-ssh",
   host_name => "$fqdn",
   tag       => "public";
edit flag offensive delete link more

answered 2013-04-03 20:10:16 -0500

ramindk gravatar image

According the docs you should be able to use a function within an if statement. I ran some tests on my system, Puppet 2.7.21 on both sides, using the following code in node file.


testing_test:    'true'


if hiera('testing_test') == 'true' {
  file { '/tmp/testing':
    ensure  => present,
    content => 'testing',

Seemed to work just fine. What version is your hiera-puppet? I'm running 1.0.0-1puppetlabs1

edit flag offensive delete link more


I think my issue is with booleans. If, in the yaml, testing: true is set, I have to refer to it as a boolean without quotes. It seems to be ...(more)

bothra gravatar imagebothra ( 2013-04-04 08:12:53 -0500 )edit

I though it might be something like that. The boolean stuff seems to catch a number of people out.

ramindk gravatar imageramindk ( 2013-04-04 11:11:15 -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



Asked: 2013-04-02 11:37:44 -0500

Seen: 629 times

Last updated: Apr 03 '13