About | FAQ | Help
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Joining array from Hiera+concat other value in erb?

Hi, I'm just starting to covert from using CSV files and extlookup to Hiera and ran into a small snag. In my manifest I have two lookups for a regular string and an array.

$cassandrasvr   = hiera("cassandrasvr"),
$cassandraport  = hiera("cassandraport"),

And my YAML file contains:

cassandraport: '9160'
cassandrasvr:
- cass1.abc.com
- cass2.abc.com
- cass3.abc.com
- cass4.abc.com
- cass1.xyz.com
- cass2.xyz.com

In my ERB template, I have the following which will print out the contents of the array, separated by a comma (except the last value).

cassandrasvr=<%= cassandrasvr.join(',') %>

And the output is this when I run Puppet:

cassandrasvr=cass1.abc.com,cass2.abc.com,cass3.abc.com,cass4.abc.com,cass1.xyz.com,cass2.xyz.com

My issue lies with the proper syntax to concatenate another value which was looked up via Hiera. I want my final output to be something like this (each value of the array concatenated with a ":9160")

cassandrasvr=cass1.abc.com:9160,cass2.abc.com:9160,cass3.abc.com:9160,cass4.abc.com:9160,cass1.xyz.com:9160,cass2.xyz.com:9160

I tried doing something like this, but it's obviously not the correct syntax since I get an error.

cassandrasvr=<%= cassandrasvr.join("<%= @cassandraport %>", ',') %>

Any help would be greatly appreciated.

Thanks!