ERB template issues in an xml document

104 views
Skip to first unread message

Mark Rosedale

unread,
Apr 14, 2015, 2:20:39 PM4/14/15
to puppet...@googlegroups.com
So I have an erb template. x.xml.erb

Inside the file I iterate over an array to add some contents to the file. It looks like so. 

<?xml version="1.0" encoding="utf-8"?>
<VCConfiguration>
<%- @x_custom.each do |value| -%>
 
<%= value %>
<%- end -%>
 
<MoreCode><%= key %></MoreCode>

However, I'm having an issue when puppet actually updates that file. If I have an array with one value in it I'd expect 1 line to be printed instead 3 lines get printed out. So the file might look like this

<?xml version="1.0" encoding="utf-8"?>
<VCConfiguration>


 
<SomeTextFromPuppet>text</SomeTextFromPuppet>


 
<MoreCode>somekey</MoreCode>

I've iterated over arrays in other templates in my puppet code without any issue of added lines, but for some reason xml files seem to be giving me trouble. Anyone else experience this, or have an idea what might be going on here? 

Neil - Puppet List

unread,
Apr 14, 2015, 7:10:58 PM4/14/15
to PuppetList

Hello

You have 3 newlines there which I've marked with Xs I expect you to get N+2.

But why do you care? Out of "I wonder why that is happening?" Is fine. Beyond that the XML is for a machine not you to spend your time reading. I hope :)

Neil


On 14 Apr 2015 16:20, "Mark Rosedale" <mros...@vivox.com> wrote:
>
> So I have an erb template. x.xml.erb
>
> Inside the file I iterate over an array to add some contents to the file. It looks like so. 
>
> <?xml version="1.0" encoding="utf-8"?>

> <VCConfiguration>X


> <%- @x_custom.each do |value| -%>

>   <%= value %>X
> <%- end -%>X


>   <MoreCode><%= key %></MoreCode>
>
> However, I'm having an issue when puppet actually updates that file. If I have an array with one value in it I'd expect 1 line to be printed instead 3 lines get printed out. So the file might look like this
>
> <?xml version="1.0" encoding="utf-8"?>
> <VCConfiguration>
>
>
>   <SomeTextFromPuppet>text</SomeTextFromPuppet>
>
>
>   <MoreCode>somekey</MoreCode>
>
> I've iterated over arrays in other templates in my puppet code without any issue of added lines, but for some reason xml files seem to be giving me trouble. Anyone else experience this, or have an idea what might be going on here? 
>

> --
> 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/88385a17-729e-47b6-8ac7-6d6ce5d3a0bd%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Mark Rosedale

unread,
Apr 14, 2015, 7:31:54 PM4/14/15
to puppet...@googlegroups.com, maillis...@iamafreeman.com
I care because I shouldn't be getting the new line if I'm using the closing -%> correct? And in any other type of file I do this very same syntax I don't get empty lines. So why is it happening here? 

Neil - Puppet List

unread,
Apr 14, 2015, 8:39:24 PM4/14/15
to Mark Rosedale, PuppetList

Glad you just care why.

so I agree you should not be seeing the extra lines.

Do you have extra whitespace after the > ?

key and value are bothering me.
Is key something else unrelated? (Should it be @key?) If you remove that line do you get the same behaviour?

Neil

Neil - Puppet List

unread,
Apr 14, 2015, 8:50:49 PM4/14/15
to Mark Rosedale, PuppetList

Another random thought, run dos2unix on the template?

Mark Rosedale

unread,
Apr 15, 2015, 1:40:49 PM4/15/15
to puppet...@googlegroups.com, mros...@vivox.com, maillis...@iamafreeman.com
So there wasn't any white space after the closing >, but I do work on a Windows box from time to time and remembered that I had copied that code snippet on that box. So runing the dos2unix on the template did indeed fix my issue and now I have the correct number of lines. 

Thanks for the help Neil. 
mjr
Reply all
Reply to author
Forward
0 new messages