r/Puppet • • Sep 22 '15

How to chain stdlib functions?

Can this be chained in puppet 3.7.3 (without future parser)?

where $::somefact = ['rEd', 'red', 'orange']

(
$somevariable_downcase = downcase($::somefact),
$somevariable_unique = unique($somevariable_downcase),
$somevariable_join = join($somevariable_unique , ",")
)
expecting end result = red,orange

I am trying to do this all on one line. Is this possible?

Edit: quick answer in case google crawls this and someone searches, i know I wish I would have found an example..

$somevariable_join = join(unique(downcase($::somefact)), ",")
0 Upvotes

4 comments sorted by

1

u/Fluxbob Sep 22 '15

I would say yes, without any testing of this. Did you tried it? What output did you get?

1

u/tek0011 Sep 22 '15

quick answer in case google crawls this and someone searches:

$somevariable_join = join(unique(downcase($::somefact)), ",")

1

u/Fluxbob Sep 23 '15

Nice one, Thanks

2

u/[deleted] Sep 23 '15

Handy hint for testing, use:

puppet apply -e 'insert code here'

So to test this you can do:

puppet apply -e '
$var = join(unique(downcase(["a", "B", "b", "c"])), ",")
notify { $var: }'