erb tempate issue

19 views
Skip to first unread message

Juan Sierra Pons

unread,
Sep 1, 2014, 5:47:34 AM9/1/14
to puppet...@googlegroups.com
Hi

I am creating a module to populate a file. The result should be like this:

uri ldap://10.10.10.1 ldap://10.10.10.2 ldap://10.10.10.3

To achieve this I am using an array with the IPs declared on the
ldap_servers array and the following erb template:

uri <% if !@ldap_servers.empty? -%>
ldap://<%= @ldap_servers %>
<% end -%>

The ouput I get is like this:

uri ldap://10.10.10.1ldap://10.10.10.2lado://10.10.10.3

Without the space between the ips.

I have also tried this (with no success):

uri <% if !@ldap_servers.empty? -%>
ldap://<%= @ldap_servers %> <%= %>
<% end -%>

I think this is an easy one but after several tries I have decided to ask here.

Thank you for your time

Best regards

--------------------------------------------------------------------------------------
Juan Sierra Pons ju...@elsotanillo.net
Linux User Registered: #257202
Web: http://www.elsotanillo.net Git: http://www.github.com/juasiepo
GPG key = 0xA110F4FE
Key Fingerprint = DF53 7415 0936 244E 9B00 6E66 E934 3406 A110 F4FE
--------------------------------------------------------------------------------------

Martin Alfke

unread,
Sep 1, 2014, 5:50:14 AM9/1/14
to puppet...@googlegroups.com
Hi.
On 01 Sep 2014, at 11:46, Juan Sierra Pons <ju...@elsotanillo.net> wrote:

> Hi
>
> I am creating a module to populate a file. The result should be like this:
>
> uri ldap://10.10.10.1 ldap://10.10.10.2 ldap://10.10.10.3
>
> To achieve this I am using an array with the IPs declared on the
> ldap_servers array and the following erb template:
>
> uri <% if !@ldap_servers.empty? -%>
> ldap://<%= @ldap_servers %>
> <% end -%>

Just add a space in front of ldap://<%= ….

>
> The ouput I get is like this:
>
> uri ldap://10.10.10.1ldap://10.10.10.2lado://10.10.10.3
>
> Without the space between the ips.
>
> I have also tried this (with no success):
>
> uri <% if !@ldap_servers.empty? -%>
> ldap://<%= @ldap_servers %> <%= %>
> <% end -%>
>
> I think this is an easy one but after several tries I have decided to ask here.
>
> Thank you for your time
>
> Best regards
>
> --------------------------------------------------------------------------------------
> Juan Sierra Pons ju...@elsotanillo.net
> Linux User Registered: #257202
> Web: http://www.elsotanillo.net Git: http://www.github.com/juasiepo
> GPG key = 0xA110F4FE
> Key Fingerprint = DF53 7415 0936 244E 9B00 6E66 E934 3406 A110 F4FE
> --------------------------------------------------------------------------------------
>
> --
> 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 puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CABS%3Dy9uyA_pwZdbgxa0m2x4K0uVWybR_YWpy6_1ACe1oQf7n1g%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Juan Sierra Pons

unread,
Sep 1, 2014, 5:54:24 AM9/1/14
to puppet...@googlegroups.com
>
> Just add a space in front of ldap://<%= ....
>


Hi

I have tried this before but I get and extra espace between uri and ldap

uri ldap://http://10.10.10.1http://10.10.10.2http://10.10.10.2

Thank you for your time

Martin Alfke

unread,
Sep 1, 2014, 5:55:41 AM9/1/14
to puppet...@googlegroups.com
Remove the space after uri and add the space in front of ldap://…
> --
> 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 puppet-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CABS%3Dy9u3-ik206G1qa0ZZM8wPKGvTUfar4DsmQGXGz4zphQYvw%40mail.gmail.com.

Juan Sierra Pons

unread,
Sep 1, 2014, 6:35:38 AM9/1/14
to puppet...@googlegroups.com
Hi

Finally I have changed to another kind on loop that works for my case

uri<% @ldap_servers.each do |server| -%>
ldap://<%= server -%>
<% end %>

Thank you for your time

Best regards

Wil Cooley

unread,
Sep 2, 2014, 12:29:11 PM9/2/14
to puppet-users group


On Sep 1, 2014 3:35 AM, "Juan Sierra Pons" <ju...@elsotanillo.net> wrote:
>
> Hi
>
> Finally I have changed to another kind on loop that works for my case
>
> uri<% @ldap_servers.each do |server| -%>
>  ldap://<%= server -%>
> <% end %>

As you've found, an explicit loop, er, iterable is better than trying to use implicit conversion of an array to a string.

An alternative is to use the 'join' method; that will put the separator only between the elements, rather than having to have it before or after each. This would be clearly better with a comma or other non-whitespace separator.

Wil

Reply all
Reply to author
Forward
0 new messages