Ask Your Question

Transform array

asked 2018-03-22 03:49:33 -0600

Hi Everyone, This sounds trivial, but I cant wrap my head around what I need to do: I have:


I want to end up with a string that looks like this:

$somestring = "node1=http://node1:2380,node2=http://node2:2380,node3=http://node3:2380"

I have tried this:

 $nodes = ['node1','node2','node3']
 $nodes2 = $nodes $merged =
 concat($nodes,$nodes2) $sorted =
 sort($merged) $test = $sorted.reduce |
 $memo, $value | {
 "${memo}=http://$value:2380," } notify
 {"nodelist is $test":}

But gives me:

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-05-03 12:27:34 -0600

updated 2018-05-03 12:28:17 -0600

Yeah, Puppet's lambdas are great, if you know how to use them. And I – personally – do my best in using them instead of leaving the Puppet domain. But this is an example, where I'm simply faster to come up with a solution in, or at least utilizing some Ruby:

$nodes  = ['node0', 'node1', 'node2']
$tuples = $ |$n| { "${n}=http://${n}:2380" }
$list   = inline_template("<%= @tuples.join(',') %>")
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


Asked: 2018-03-22 03:49:33 -0600

Seen: 20 times

Last updated: May 03