Created
March 16, 2018 11:12
-
-
Save WhatsARanjit/bd5d3bc28a18c8ea888778212f260a09 to your computer and use it in GitHub Desktop.
ENV arrays merge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function test::merge_env_arrays ( | |
Array $array_one, | |
Array $array_two, | |
) >> Array { | |
$hash_one = $array_one.reduce({}) |$memo, $var| { | |
$v = $var.split('=') | |
merge($memo, { $v[0] => $v[1] }) | |
} | |
$hash_two = $array_two.reduce({}) |$memo, $var| { | |
$v = $var.split('=') | |
merge($memo, { $v[0] => $v[1] }) | |
} | |
$merged_hashes = merge($hash_one, $hash_two) | |
$merged_hashes.map |$item| { "${item[0]}=${item[1]}" } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@puppet2017 /opt/puppetlabs/puppet/modules]# puppet apply -e 'notice(test::merge_env_arrays(["1=a", "2=b"], ["1=x", "2=y", "3=z"]))' | |
Notice: Scope(Class[main]): [1=x, 2=y, 3=z] | |
Notice: Compiled catalog for puppet2017.3.0.puppetlabs.vm in environment production in 0.04 seconds | |
Notice: Applied catalog in 0.26 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment