Ask Your Question
0

hiera automatic parameter lookup does not appear to work

asked 2017-02-27 20:55:15 -0500

wfsaxton gravatar image

updated 2017-02-27 21:36:59 -0500

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 flag offensive close merge delete

Comments

1

maybe you are missing the class parameters profile::gogs($port = '') {}

c4f4t0r gravatar imagec4f4t0r ( 2017-02-28 02:56:58 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2017-02-28 06:21:26 -0500

puser gravatar image

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.

edit flag offensive delete link more
1

answered 2017-03-01 07:13:45 -0500

rnelson0 gravatar image

updated 2017-03-01 07:14:30 -0500

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/...

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: 2017-02-27 20:55:15 -0500

Seen: 71 times

Last updated: Mar 01