On Wednesday, March 6, 2013 at 12:49:44 AM UTC-6, Robert Citek wrote:
>
> Hello all, 
>
> How does one enter multi-line content using 'puppet resource file ...' 
> at the command line? 
>
> For example, I am trying to create a file called /tmp/hw.txt with two 
> lines of content: 
>
> $ cat /tmp/hw.txt 
> hello 
> world 
>
> This does not work: 
>
> $ puppet resource file hello_world \ 
>   path=/tmp/hw.txt \ 
>   ensure=file \ 
>   content="hello\nworld\n" 
>
> This does, but use "puppet apply" : 
>
> cat <<"eof" | puppet apply 
> file { "hello_world": 
>   path => "/tmp/hw.txt", 
>   ensure => "file", 
>   content => "hello\nworld\n", 
> } 
> eof 
>
> Does anyone have any pointers on how to construct the content= line so 
> that I can get two lines of text? 
>
>

You did not say exactly what "does not work" means, but I suppose the 
problem is that you get literal "\n" in the file instead of newlines.  The 
shell will not convert those when you execute the specific command you 
presented, and I guess Puppet expects to receive a literal value.  In that 
case, this is more a shell problem than a Puppet problem, and probably it 
can be solved via the shell.  Details vary depending on which shell you are 
using, but there are multiple possibilities, among them:

1. Include literal newlines in your parameter instead of "\n".  In bash, at 
least, this works as long as the newlines are quoted.  For example:

$ puppet resource file hello_world \ 
path=/tmp/hw.txt \ 
ensure=file \ 
content="hello
world
"

2. Use the shell's form for C-style escapes.  In bash, that would be:

$ puppet resource file hello_world \ 
path=/tmp/hw.txt \ 
ensure=file \ 
content=$'hello\nworld\n'

3. Obtain the wanted value as the output of a command.  In bash, that would 
be:

$ puppet resource file hello_world \ 
path=/tmp/hw.txt \ 
ensure=file \ 
content="`echo -e 'hello\nworld'`"

(By itself, however, this last alternative cannot produce a trailing 
newline in the content, as shell command substitution eats those.)


John

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/f1b583f7-0343-47a7-99f8-4e8ef6dfe6d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to