0

Given the hiera list (example values):

simplekey:
  hosts:
    - 'host1:8080'
    - 'host2:8080'
  [...]

When using ERB template, this code:

<% @simplekey.sort.each do |key, value| -%>
  <%= key %>: <%= value %>,
<% end -%>

results in

  hosts: ["host1:8080", "host2:8080"],

When migrating the code to EPP, a similar code:

<% $simplekey.each |$key, $value| { -%>
  <%= $key %>: <%= $value %>,
<% } -%>

results in (notice the missing quotation marks):

  hosts: [host1:8080, host2:8080],

Is there any way I can print the hosts array with quotation marks?

Puppet version: 6.23.0

pascalre
  • 305
  • 1
  • 4
  • 20
  • I find your claim that the ERB version automatically introduces quotation marks surprising. That's not what I would expect from the code presented alone. – John Bollinger Jul 01 '21 at 19:22

1 Answers1

0

Super simple - just put the quotes in the EPP:

<% $simplekey.each |$key, $value| { -%>
  "<%= $key %>": <%= $value %>,
<% } -%>
Jon
  • 3,573
  • 2
  • 17
  • 24
  • This however does not work if you would like to use .join(',') on array and have the elements of array surrounded by quotes. – Kris Avi Mar 31 '22 at 15:15
  • your answer actually would output something like: `"hosts": [host1:8080, host2:8080],` not sure what exactly would happen if you put quotation marks on value field, but I guess something like: `"hosts": "[host1:8080, host2:8080]",` That again doesn't seem like wished result. – Kris Avi Mar 31 '22 at 15:24