string-concatenation


How do you concatenate strings in a Puppet .pp file?


Here is my naive approach:
# puppet/init.pp
$x = 'hello ' +
'goodbye'
This does not work. How does one concatenate strings in Puppet?
Keyword variable interpolation:
$value = "${one}${two}"
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.
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.
$zookeeperservers = [ 'node1.example.com', 'node2.example.com', 'node3.example.com' ]
$mesosZK = join([ "zk://" , join($zookeeperservers,':2181,') ,":2181/mesos" ],'')
resulting value of $mesosZK
zk://node1.example.com:2181,node2.example.com:2181,node3.example.com:2181/mesos
Another option not mentioned in other answers is using Puppet's sprintf() function, which functions identically to the Ruby function behind it. An example:
$x = sprintf('hello user %s', 'CoolUser')
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.
puppet apply -e ' $y = "Hello" $z = "world" $x = "$y $z" notify { "$x": } '
notice: Hello world
notice: /Stage[main]//Notify[Hello world]/message: defined 'message' as 'Hello world'
notice: Finished catalog run in 0.04 seconds
The following works as well:
$abc = "def"
file { "/tmp/$abc":
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.

Related Links

ConcatRelated Function Returns All Values
In java properties file itself can we concatenate two or more than two variables together?
“No message” when writing string with console.log()
Moqui:We can use create an view with concatenating two or more columns as single column. simple can we do concatenatio in moqui view creqtion.
Error in ConcatRelated
String Concatenating functions in Progress 4GL?
sybase - simple concatenation
How do you concatenate strings in a Puppet .pp file?

Categories

HOME
azure-stream-analytics
google-cloud-platform
twig
mjml
interface
mstest
soa
settings
jax-ws
32bit-64bit
octave
why3
http-post
azure-powershell
package.json
feathersjs
fileserver
aggregation
expressionengine3
tiki-wiki
custom-controls
cart
baidu-map
imx6
reactivekit
protein-database
jvmti
signals-slots
postgresql-8.4
angular-http
importerror
clang++
apache-spark-dataset
memory-mapping
snapchat
lampp
serde
geotiff
x-ray
trojan
aquamacs
qtranslate
semantic-logging
pdf-conversion
shinobi
cudd
mapinfo
dup
cortex-m
fink
qbxml
terracotta
qt5.2
r-package
jdi
video-player
lasso
typemock
apache-commons-daemon
canvg
git-ftp
zxspectrum
public-html
ejb-2.x
angular-gettext
browserify-shim
cocos3d
paw
cbind
mobility
winginx
dct
away3d
kaleidoscope
cardreader
qi4j
gobject-introspection
role
listactivity
google-ajax-api
maven-1
easyb
zen
pagemethods
strtod
purepdf
firefox-3
online-storage
leader

Resources

Encrypt Message