puppet template remove the last comma
This is actually a Ruby problem rather than a Puppet problem. Since this is an array, just change the .each
to .each_with_index
. Then you can wrap the final comma in a check to see whether the current index value is one less than the size of the index. For example, the following code adds a comma only if the current market
is not the last one in the array:
<% @markets.each_with_index do |market, i| -%>
and then
}<%= ',' if i < (@markets.size - 1) %>
I saw on a puppet labs site (https://ask.puppetlabs.com/question/4195/joining-array-from-hieraconcat-other-value-in-erb/) this form of solution.
<%= quorum.map{ |srv| "#{srv}:#{portNum}" }.join(',') %>
This code lets you take an array and create a variation of each element then join them all together with the appropriate join text (not including a spurious comma at end).