Reputation: 159
I want to put a few values in a file using puppet, but when I do the following in a ruby template:
<% @_zoo_cfgs.each do |zooconfig| -%>
<%=zooconfig -%>
<% end -%>
I get the below content in the generated file:
server.1=a1-dev-mem333.lab.lynx-connected.com:2888:3888(trailing whitespace)
But I want the below content:
server.1=a1-dev-mem333.lab.lynx-connected.com:2888:3888(no trailing whitespace)
with no extra whitespace in the file before or after the value. Could anyone please let me know how could this be done?
Upvotes: 4
Views: 4894
Reputation: 113
If the whitespace is part of the value from your variable, use Ruby string functions to get rid of it, e.g.
<%= zooconfig.rstrip %>
Upvotes: 0
Reputation: 180351
When you close an ERB tag with -%>
, any newline immediately following the closing tag is suppressed. If the next character is anything else, however, such as a space character, then there is no suppression. Perhaps more significantly in your case, leading whitespace on the following line of your template is not suppressed under any circumstances.
There are at least two ways to handle the situation.
<% @_zoo_cfgs.each do |zooconfig| -%>
<%=zooconfig -%>
<% end -%>
<%# assumes that @_zoo_cfgs is an array: -%>
<%= @_zoo_cfgs.join("\n") -%>
Upvotes: 5