# hiera automatic parameter lookup does not appear to work

I'm trying to convert my manifests to use automatic lookups instead of hiera-function lookups and it does not appear to be working. Here are my hiera yaml and profile manifests:

my.yaml:

profile::gogs::port: 8081


gogs.pp:

 class profile::gogs {

$myport = hiera('profile::gogs::port')$myport2 = $profile::gogs::port$myport3 = $port notify {"myport:$myport, myport2: $myport2, myport3:$myport3":}


I then run my puppet agent and get the following notify output:

$sudo -i puppet agent -vt --environment gitserver . . Notice: /Stage[main]/Profile::Gogs/Notify[myport: 8081, myport2: , myport3: ]/message: defined 'message' as 'myport: 8081, myport2: , myport3: '  So hiera can obviously see the value just fine, but the syntax I tried for the automatic parameter lookup (myport2 & myport3) seem to both fail. Perhaps I'm doing something wrong? NOTE: I'm using Puppet 4.3.2 with the standard roles/profiles patterns and r10k. edit retag close merge delete ## Comments 1 maybe you are missing the class parameters profile::gogs($port = '') {}

( 2017-02-28 02:56:58 -0600 )edit

Sort by » oldest newest most voted

Even though the Hiera parameter is named as such to belong in your manifest, i.e. profile::gogs::port, you still need a class parameter to bring it into the manifests.

class profile::gogs(
$port = '<someDefaultPort>', #Important piece msising. ) {$myport = hiera('profile::gogs::port')
$myport2 =$profile::gogs::port
$myport3 =$port

notify {"myport: $myport, myport2:$myport2, myport3: $myport3":}  If Hiera is correctly configured this will be your fix. Also note that facter values do not need parameters, you can use them anywhere in your manfiests like $::osfamily without specifying a parameter.

Also note that the parameter name is the short name, $port. You do not need the fully qualified named like $profile::gogs::port but you do in hiera.

more

You're not actually using automatic parameter lookup in this case. To use APL, the parameter name needs to match the key in hiera. In other words, $myport2 =$profile::gogs::port can be fixed in one of two ways:

class profile::gogs (
$port, # no change to hiera, the value of profile::gogs::ports (8081) is used ) { .. }  or class profile::gogs ($myport2,  # change the hiera key profile::gogs::ports to profile::gogs::myport2
) { .. }


Automatic parameter lookup does have some limitations, with hash keys in particular, more information at https://docs.puppet.com/hiera/latest/...

more