Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 415
rlandster Avatar asked Feb 14 '13 22:02

rlandster


People also ask

How do you concatenate strings in SAP ABAP?

You can (starting with ABAP 7.02) use && to concatenate two strings. Data: foo TYPE string, bar TYPE string, foobar TYPE string. foo = 'foo'.

What is the correct way to concatenate the strings?

You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.

Can you concatenate strings in Yaml?

Concatenating strings and/or variablesThe standard YAML format does not support the notion of string concatenation. Since concatenating string values is a common pattern in easyconfig files, the EasyBuild framework defines the ! join operator to support this.


2 Answers

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.

like image 152
czervik Avatar answered Oct 21 '22 18:10

czervik


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 
like image 33
Niels Basjes Avatar answered Oct 21 '22 17:10

Niels Basjes