Here is my naive approach:
# puppet/init.pp
$x = 'hello ' +
'goodbye'
This does not work. How does one concatenate strings in Puppet?
Here is my naive approach:
# puppet/init.pp
$x = 'hello ' +
'goodbye'
This does not work. How does one concatenate strings in Puppet?
Another option not mentioned in other answers is using Puppet's
sprintf()
function, which functions identically to the Ruby function behind it. An example:Verified to work perfectly with puppet. As mentioned by chutz, this approach can also help you concatenate the output of functions.
The following worked for me.
The following works as well:
As stated in docs, you can just use ${varname} interpolation. And that works with function calls as well:
Could not use {} with function arguments though: got
Syntax error at '}'
.You could use the join() function from puppetlabs-stdlib. I was thinking there should be a string concat function there, but I don't see it. It'd be easy to write one.
I use the construct where I put the values into an array an then 'join' them. In this example my input is an array and after those have been joined with the ':2181,' the resulting value is again put into an array that is joined with an empty string as separator.
resulting value of $mesosZK
Keyword variable interpolation:
Source: http://docs.puppetlabs.com/puppet/4.3/reference/lang_variables.html#interpolation
Note that although it might work without the curly braces, you should always use them.