Skip to content

Instantly share code, notes, and snippets.

@kwilczynski
Created April 1, 2012 23:05
Show Gist options
  • Save kwilczynski/2279315 to your computer and use it in GitHub Desktop.
Save kwilczynski/2279315 to your computer and use it in GitHub Desktop.
Puppet hash merge and deep merge example ...
matti@acrux ~/reject $ RUBYLIB=. cat - | puppet apply
$a = { 'abc' => 123, 'def' => 456}
$b = { 'abc' => 123, 'def' => 999}
notice dump(merge($a, $b))
notice dump(merge($b, $a))
notice: Scope(Class[main]): {"abc"=>"123", "def"=>"999"}
notice: Scope(Class[main]): {"abc"=>"123", "def"=>"456"}
notice: Finished catalog run in 0.07 seconds
matti@acrux ~/reject $ RUBYLIB=. cat - | puppet apply
$a = { 'a' => {'b' => [4, 5, 6], 'c' => { 'd' => 'foo' }, 'x' => [7, 8, 9] }}
$b = { 'a' => {'b' => [1, 2, 3], 'c' => { 'd' => 'bar' }, 'x' => 'xyz' }}
notice dump(deep_merge($a, $b))
notice dump(deep_merge($b, $a))
notice: Scope(Class[main]): {"a"=>{"b"=>["1", "2", "3"], "x"=>"xyz", "c"=>{"d"=>"bar"}}}
notice: Scope(Class[main]): {"a"=>{"x"=>["7", "8", "9"], "b"=>["4", "5", "6"], "c"=>{"d"=>"foo"}}}
notice: Finished catalog run in 0.10 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment