Ask Your Question

how to use newline character('\n') in puppet template

asked 2015-03-18 05:37:49 -0600

YOGESH DANGCHE gravatar image

updated 2015-03-21 03:30:51 -0600

doc75 gravatar image


$values = [val1, val2, otherval]
        ensure => present,
        path => "C:\\Software\demo.txt",
        content => template('temp/temp.rb'),


<% @values.each do |val| -%>
Some stuff with <%= val %>
<% end -%>

I want the output in seperate line but it is not working. it gives the output as:

Some stuff with val1 Some stuff with val2 Some stuff with otherval

but I want the output like:

Some stuff with val1
Some stuff with val2
Some stuff with otherval

please help me.

edit retag flag offensive close merge delete


It's bizzare, when I test that with puppet 3.6.2 or 3.7.4 it works correctly. perhaps it is a windows vs Linux difference?

DarylW gravatar imageDarylW ( 2016-08-03 16:55:07 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-08-03 08:40:29 -0600

Hoppertron gravatar image

For variables, it's

<%= "#{@my_variable}\r\n" %>

For hard-coded values, it's

<%= "#{'SomeValue'}\r\n" %>

(Note the use of single apostrophes!)
Tested and confirmed working on puppet 3.8.7.

edit flag offensive delete link more


I think the \r\n in your case is probably what will make the difference, since his destination file is on C:\\, it may be a windows vs Linux issue, where the template will put in a \n (since there is no -%> on the stuff line), and adding extra \n doesn't do anything for him.

DarylW gravatar imageDarylW ( 2016-08-03 16:56:43 -0600 )edit

If you were to edit the template file using a windows machine, and inject the windows end of line characters on every line you would probably see the correct results without manually adding the \r\n to the string being put out.

DarylW gravatar imageDarylW ( 2016-08-03 16:57:46 -0600 )edit

answered 2015-03-21 03:32:10 -0600

doc75 gravatar image


You can try to modify your template like this:

<% @values.each do |val| -%>
Some stuff with <%= "#{val}\n" %>
<% end -%>

Hope this helps

edit flag offensive delete link more


This didn't work.

deppfx gravatar imagedeppfx ( 2015-11-23 21:00:27 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-03-18 05:37:49 -0600

Seen: 4,124 times

Last updated: Aug 03 '16