Is it possible to make a deep merge of 2 hashes in puppet code?

27 views
Skip to first unread message

Francois Lafont

unread,
Aug 25, 2017, 2:46:58 PM8/25/17
to puppet...@googlegroups.com
Hi @all, :)

I would like to make a deep merge between 2 hashes:

1. directly in puppet code,

2. with the same behavior that the deep merging of the
lookup() option (when set with 'deep' as merge policy
of course).

I have tried the deep_merge() function from stdlib (version
v4.19.0 in my case) with this code:

--------------------
$h1 = {
key1 => {'subkey' => ['foo', 'bar']},
key2 => {'subkey' => ['foo']},
}

$h2 = {
key2 => {'subkey' => ['bar']}
}

notice(deep_merge($h1, $h2))
--------------------

And here is the result (I have just added indentation):

Notice: Scope(Class[main]):
{
key1 => {subkey => [foo, bar]},
key2 => {subkey => [bar]},
}

But the deep merge I would like should give:

{
key1 => {subkey => [foo, bar]},
key2 => {subkey => [foo, bar]},
}

So my question is: in puppet code, is it possible to make
a deep merge between 2 hashes with the same merge policy
as the lookup() built-in function?

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages