Ask Your Question
1

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

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

YOGESH DANGCHE gravatar image

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

doc75 gravatar image

#site.pp

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

#temp.erb

<% @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

Comments

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 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

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

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

Comments

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 -0500 )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 -0500 )edit
0

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

doc75 gravatar image

Hello,

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

Comments

This didn't work.

deppfx gravatar imagedeppfx ( 2015-11-23 21:00:27 -0500 )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

Stats

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

Seen: 1,601 times

Last updated: Aug 03 '16