Ask Your Question
0

hiera_hash fails to fetch values from hieradata when using same variable name - is this a bug?

asked 2016-08-09 02:43:43 -0500

TimmyC gravatar image

php7web.pp:

class profile::php7web (
  $apache_vhosts_defaults = hiera_hash('profile::php7web::apache_vhosts_defaults'),
) {
  notify { "$apache_vhosts_defaults": }
}

common.yaml:

profile::php7web::apache_vhosts_defaults:
  port: 80

dev.yaml:

profile::php7web::apache_vhosts_defaults:
 setenv: ['SYMFONY_ENV dev']

The output is: setenv: { ['SYMFONY_ENV dev'] } .

However, if I change php7web.pp to:

class profile::php7web (
  $fff = hiera_hash('profile::php7web::apache_vhosts_defaults'),
) {
  notify { "$fff": }
}

The output is: { port: 80, setenv: ['SYMFONY_ENV dev'] }

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-08-09 14:43:00 -0500

jorhett gravatar image

updated 2016-08-25 14:57:35 -0500

DarylW gravatar image

So the first one is being set by automatic parameter lookup. The auto lookup finds the highest precedence value of the name on the left and returns it. This is why the first example gets a single, first result value.

If it can't find a variable of the same name, (like "fff") then it uses the backup value you've provided--the hiera_hash() call.

This is working exactly as intended: https://docs.puppet.com/hiera/3.2/pup...

That being said, stop using hiera_hash() and use lookup() instead. It is considerably more flexible, and this page describes how to get merged hash results in automatic parameter lookup: http://my.safaribooksonline.com/book/operating-systems-and-server-administration/9781491907993/14dot-improving-the-module/lookingupinputfromhiera_html

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: 2016-08-09 02:43:43 -0500

Seen: 92 times

Last updated: Aug 25 '16