Home > Puppet > Array join in Puppet manifest

Array join in Puppet manifest

Maybe some of you noticed that as of time of writing this blog – there is a split() function available in puppet declarative language, but there is no join()? Well that puzzled me too, because I wanted to join an array and serve it as a content of a file. Well, PuppetLabs made inline_template() available to us lazy users, so we can use all the erb code we want inside our manifests! So, how did I join my array? Here is nice example:

$routes = [' via', ' via'],
$fullroute = inline_template("<%= (routes).join('\n') + \"\n\" %>")

Now, I can feed $fullroute to some file as content and that’s it!

file { '/etc/sysconfig/network-scripts/route-eth0':
  ensure  => file,
  content => "$fullroute",

Pretty neat, isn’t it? 🙂

Categories: Puppet Tags: , ,
  1. June 21, 2014 at 10:12 am

    Or use the `join` function from stdlib:

    $fullroute = join($route, ‘”\n”)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: