Ask Your Question

hiera_hash not merging hash

asked 2016-09-26 14:54:19 -0600

mazdajai gravatar image

updated 2016-09-26 21:42:53 -0600

I have two set of hash in the module and in yaml.

I am expected to see values in the module would override the ones in common but it didn't happen and got undefined instead. Thoughts?

*Edited to post solution.


     $defaults = {
      pre  => '',
      post => '',
      save     => '',
    $options  = merge( hiera_hash('networker::options'),$networker::defaults )
$pre  = $networker::options[pre] #Edited 
$post = $networker::options[post] #Edited 
$save = $networker::options[save] #Edited


    pre             : 'foo'
    save            : 'bar'


Post : <%= scope.lookupvar('networker::post') %>;
Pre : <%= scope.lookupvar('networker::pre') %>;
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-09-26 17:07:58 -0600

lavaman gravatar image

You appear to be referencing undefined variables in your erb template. From your code, you'd need to use @options['pre'], @options['post'], etc instead of scope.lookupvar.

edit flag offensive delete link more


You nailed it, I forgot to put the hash value back to the variable. Thanks lavaman.

mazdajai gravatar imagemazdajai ( 2016-09-26 21:40:08 -0600 )edit

answered 2016-09-26 15:03:45 -0600

DarylW gravatar image

You are using the method backwards..

The first argument should be the hash you want to merge to, and the second argument should be the hash you want to merge from.

Merges two or more hashes together and returns the resulting hash.


$hash1 = {'one' => 1, 'two' => 2}
$hash2 = {'two' => 'dos', 'three' => 'tres'}
$merged_hash = merge($hash1, $hash2)
# The resulting hash is equivalent to:
# $merged_hash =  {'one' => 1, 'two' => 'dos', 'three' => 'tres'}

When there is a duplicate key, the key in the rightmost hash "wins." Type: rvalue.
edit flag offensive delete link more


I tried swapping the order in merge () but doesn't work - I expect to see the blank that I set in the modules but still getting undefined.

mazdajai gravatar imagemazdajai ( 2016-09-26 15:35:36 -0600 )edit

Ah, so you had two problems, your above problem was why you weren't seeing a value, and this problem would have been a logic error with your data!

DarylW gravatar imageDarylW ( 2016-09-27 08:20:52 -0600 )edit

Yes sir. I should have known when I see 'undefined' being returned, it was from ruby template. Interesting, documentation refer 'nil' from Ruby template and mention nothing about 'undefined'.

mazdajai gravatar imagemazdajai ( 2016-09-27 16:42:27 -0600 )edit

I think it has more to do with the erb parsing... once I accidently commented out my code in an erb assignment <%= #'thing' %> and I believe I got a similar error. (you CAN comment out code in a regular block <% %>, just not in an assignment). I think there is some other checking that goes on

DarylW gravatar imageDarylW ( 2016-09-28 08:34:35 -0600 )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: 2016-09-26 14:54:19 -0600

Seen: 209 times

Last updated: Sep 26 '16