FAQ
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?

Regards,
- Robert

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Felix Frank at Mar 12, 2013 at 12:36 pm
    Hi,

    at first glance, it doesn't seem to be possible.

    I had never thought of using puppet resource in this way. Is there a
    reason why you prefer it over puppet apply?
    On 03/06/2013 07:49 AM, 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?

    Regards,
    - Robert
    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Robert Citek at Mar 12, 2013 at 7:55 pm
    Just preference and consistency. We've been using puppet as a
    substitute for shell commands that use the 'command [options]
    arguments ... ' pattern and 'puppet resource ...' matches that
    pattern nicely. But if by using here-documents we can match the
    pattern pretty closely and we gain the additional functionality, we'll
    go that way.

    Using 'puppet apply' with a here-document ....

    puppet apply <<"eof"
    file { "hello_world":
       path => "/tmp/hw.txt",
       ensure => "file",
       content => "hello\nworld\n",
    }
    eof

    ... looks pretty close to using arguments to 'puppet resource' ...

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

    ... but actually works. :)

    Regards,
    - Robert

    On Tue, Mar 12, 2013 at 8:36 AM, Felix Frank
    wrote:
    Hi,

    at first glance, it doesn't seem to be possible.

    I had never thought of using puppet resource in this way. Is there a
    reason why you prefer it over puppet apply?
    On 03/06/2013 07:49 AM, 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?

    Regards,
    - Robert
    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    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+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Massimiliano Adamo at Sep 22, 2015 at 1:04 pm
    Il giorno mercoledì 6 marzo 2013 07:49:44 UTC+1, Robert Citek ha scritto:
    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"
    one of the following will work (or either both):
    content => inline_template('<%= "hello" + "\n" + "world" %>'),
    content => inline_template('<%= "hello\nworld" %>'),


    --
    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+unsubscribe@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/e27dd8a1-0442-4c47-af8b-8d00c0295979%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jcbollinger at Sep 23, 2015 at 1:17 pm

    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 puppet-users+unsubscribe@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedMar 6, '13 at 6:49a
activeSep 23, '15 at 1:17p
posts5
users4
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase