My example is an epp template.
What name does the variable have? $ntp? And: is this a hash with servers key
set to an array?
In this case your erb (!) template can look like the following:
<% @ntp[’servers’].each { |server| -%>
server: <%= server %>
<% } -%>
> On 28. Mar 2023, at 14:37, Laci D <[email protected]> wrote:
>
> Thank you Martin!
>
> I used your example and I think something is missing.
> Since "servers" is under "ntp" in the hiera file (see example in my original
> email) maybe we need to define that in the erb file?
>
>
> Error: Could not retrieve catalog from remote server: Error 500 on SERVER:
> Internal Server Error: org.jruby.exceptions.SyntaxError: (SyntaxError)
> /etc/puppetlabs/code/modules/site/templates/ntp/ntp.conf.erb:6: syntax error,
> unexpected tSTRING_BEG
> _erbout.<< "server: ".freeze; _erbout.<<((...
> ^
> Warning: Not using cache on failed catalog
> Error: Could not retrieve catalog; skipping run
>
> On Tuesday, March 28, 2023 at 2:57:23 AM UTC-4 Martin Alfke wrote:
>> You must iterate as servers is an array:
>>
>> <% $servers.each |$server| { -%>
>> server: <%= $server %>
>> <%- } -%>
>>
>>
>>> On 27. Mar 2023, at 22:21, Laci D <[email protected] <>> wrote:
>>>
>>
>>> I'm working on defining NTP servers from Hiera.
>>>
>>> For Linux servers I have been using puppetlabs-ntp, which has been working
>>> nicely. Now I need to add support for FreeBSD. Above module doesn't support
>>> FreeBSD but I can edit ntp.conf with file resource type.
>>>
>>> This is where things got complicated, file adds extra ["..."] around the
>>> value form hiera, since it's an array. Array type is required for
>>> puppetlabs-ntp
>>> Question is how can I get rid of the extra squarely braces and double
>>> quotes?
>>> Rather than using a static file I'd like to stick to hiera since the ntp
>>> can very based on datacenter.
>>>
>>> /etc/ntp.conf
>>> server ["169.254.169.123"]
>>>
>>> Desired /etc/ntp.conf
>>> server 169.254.169.123
>>>
>>> hieradata/site.yaml
>>> ntp:
>>> servers:
>>> - 169.254.169.123
>>>
>>> templates/ntp/ntp.conf.erb
>>> server <%= @ntp['servers'] %>
>>>
>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Puppet Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected] <>.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/puppet-users/848044f1-888d-44b3-8098-2c3569eb1608n%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/puppet-users/848044f1-888d-44b3-8098-2c3569eb1608n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/1d68b2ef-0c4f-425f-a84d-3cc22e6f750an%40googlegroups.com
>
> <https://groups.google.com/d/msgid/puppet-users/1d68b2ef-0c4f-425f-a84d-3cc22e6f750an%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/5EF6A18F-0F46-42A8-AE13-BB37F700A64E%40gmail.com.