Ask Your Question
0

Hiera working on command line but not in my class?

asked 2015-02-17 13:37:32 -0600

Red Cricket gravatar image

Hi,

I have having trouble understanding why my parameter is undefined. I can find the key/value via hiera command line like so ...

root@ost-puppet-el7-001 ~]# hiera haproxy_cert_filename
/etc/haproxy/thecertfile

This is my hiera.yaml:

[root@ost-puppet-el7-001 ~]# cat /etc/puppetlabs/puppet/hiera.yaml 
---
:backends:
  - yaml
:hierarchy:
  - defaults
  - "%{clientcert}"
  - "%{environment}"
  - global

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /var/lib/hiera on *nix
# - %CommonAppData%\PuppetLabs\hiera\var on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir: /root/puppetmaster/hiera/ost-el7

This is my defaults.yaml file:

[root@ost-puppet-el7-001 ~]# cat /root/puppetmaster/hiera/ost-el7/defaults.yaml
---
haproxy_cert_filename: "/etc/haproxy/thecertfile"

testhiera2::haproxy_cert_filename: "%{hiera{'haproxy_cert_filename')}"

Here is a simple test class I made:

[root@ost-puppet-el7-001 ~]# cat /etc/puppetlabs/puppet/modules/testhiera2/manifests/init.pp 
class testhiera2 (
        $haproxy_cert_content = 'param_value' ,
    $haproxy_cert_filename = 'unknonw',
) {

        #notify {"two cert is $haproxy_cert_content":}
        notify {"two Cert filename is ${haproxy_cert_filename}":}
}

When I run that class on my puppet master I get this output ...

[root@ost-puppet-el7-001 ~]# puppet apply -e 'include testhiera2'
Notice: Compiled catalog for ost-puppet-el7-001.example.com in environment production in 0.09 seconds
Notice: two Cert filename is 
Notice: /Stage[main]/Testhiera2/Notify[two Cert filename is ]/message: defined 'message' as 'two Cert filename is '
Notice: Finished catalog run in 0.18 seconds

Why don't I get "[two Cert filename is /etc/haproxy/thecertfile]" in my output?

Thanks

edit retag flag offensive close merge delete

Comments

Does it make a difference, if in the hieradata file you scope it with the classname such as `testhiera2 ::haproxy_cert_filename: "/etc/haproxy/thecertfile"` ?

kaizenCoder gravatar imagekaizenCoder ( 2015-02-17 19:53:23 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-02-18 12:22:52 -0600

GregLarkin gravatar image

Your defaults.yaml has a subtle syntax error that I would expect to generate a run-time error, but doesn't:

testhiera2::haproxy_cert_filename: "%{hiera{'haproxy_cert_filename')}"

should be:

testhiera2::haproxy_cert_filename: "%{hiera('haproxy_cert_filename')}"

Note the change from hiera{ to hiera( in the function call.

As an aside, is there a reason that you use the hiera() function call in your hiera data file, rather than assigning the value directly to the variable that your class is looking up (e.g. testhiera2::haproxy_cert_filename)? I guess if you are re-using that value in several other Hiera values, that would make sense.

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

Stats

Asked: 2015-02-17 13:37:32 -0600

Seen: 148 times

Last updated: Feb 18 '15