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

  - "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?

  • 2
    You can use to_json from stdlib. – jordanm Feb 16 '18 at 19:33
  • @jordanm Does this work with puppet ERB? – nitins Feb 17 '18 at 11:10

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_json = to_json($master_servers)

In your ERB:

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

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.