1

I have a array defined in the following format in hiera.

 master_servers:
  - "stage-01.com"
  - "stage-02.com"

I am trying to populate the config file with ERB in the following format

discovery.zen.ping.unicast.hosts: ["stage-01.com", "stage-02.com" ]

I tried the following in ERB, but the array comes off as a single string.

discovery.zen.ping.unicast.hosts: <%= scope['::profiles::xxx::master_servers'] %>

The profiles::xxx::master_servers is correctly doing the hiera lookups.

How can I correct my ERB?

nitins
  • 2,579
  • 15
  • 44
  • 68

1 Answers1

2

Expanding the comment from jordanm - you can use the to_json function from the puppetlabs-stdlib module - source.

In your Puppet manifest:

class profiles::xxx(
  $master_servers,
) {
  $master_servers_json = to_json($master_servers)
  ...
}

In your ERB:

discovery.zen.ping.unicast.hosts: <%= scope['::profiles::xxx::master_servers_json'] %>
Craig Watson
  • 9,575
  • 3
  • 32
  • 47