strange line wrapping behavior

50 views
Skip to first unread message

tobias...@gmail.com

unread,
Nov 17, 2015, 11:08:34 AM11/17/15
to Puppet Users
Hi,

I got a file resource

  file {'/usr/java/jboss-as/server/somesoftware/deploy/jontram-ds.xml':
    ensure  => file,
    owner   => 'root',
    group   => 'root',
    mode    => '0655',
    content => template('somesoftware/jboss/jontram-ds.xml.erb'),
    require => [ Class['somesoftware::cpfiles'], somesoftware::mariadb::createdb [ $db_name ] ],
  }

The second last line is obviously to long (over 80 lines). It works in one line but I get a puppet-lint error. I would like to cut it it two. My first thought was to use the '\'

like
    require => [ Class['somesoftware::cpfiles'],\
somesoftware::mariadb::createdb [ $db_name ]
  }

but then I get an error

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at '\'; expected ']' at  ...

It works if I just press enter at the end of the line and write the rest on the next line (without the \).

So I wonder is it right to not use \ for line wrapping? If yes where can I find documentation about that behavior?


Garrett Honeycutt

unread,
Nov 17, 2015, 2:35:49 PM11/17/15
to puppet...@googlegroups.com
Hi Tobias,

Somehow line length was added to the style guide, though Puppet does not
provide a mechanism, such as `\` to denote line wrapping. While not
having huge lines is a good idea, adhering to an arbitrary limit without
the ability to wrap to the next line is not. Suggest turning it off. In
fact, we disable it by default[1] when creating new modules.

You can limit the length of your require like this

file { '/usr/java/jboss-as/server/somesoftware/deploy/jontram-ds.xml':
ensure => file,
owner => 'root',
group => 'root',
mode => '0655',
content => template('somesoftware/jboss/jontram-ds.xml.erb'),
require => [Class['somesoftware::cpfiles'],
Somesoftware::Mariadb::Createdb[$db_name],
],
}

In general, putting elements of an array on multiple lines helps
readability, especially when reviewing diffs.

[1] -
https://github.com/puppetlabs/puppet/blob/1a557254012447a4f0a2e01eeebaf52c75ab6f80/lib/puppet/module_tool/skeleton/templates/generator/Rakefile#L3

Best regards,
-g

--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

tobias...@gmail.com

unread,
Nov 17, 2015, 2:51:31 PM11/17/15
to Puppet Users
Hi G,

sounds great.

How would you use the indentation in

Somesoftware::Mariadb:: ...

The same position as the require? Or two characters on the right? I'm asking because resources can be already indented (e.g. two chars) and the second line then starts at position 1 on the new line.

I'm still wondering when to use the Backslash. On some sources (e.g. http://stackoverflow.com/questions/11406234/puppet-how-can-i-wrap-a-command-into-two-line-if-80-characters ) it's recommended but it didn't work on my machine.


Am Dienstag, 17. November 2015 20:35:49 UTC+1 schrieb Garrett Honeycutt:

Garrett Honeycutt

unread,
Nov 17, 2015, 3:11:39 PM11/17/15
to puppet...@googlegroups.com

On 11/17/15 2:51 PM, tobias...@gmail.com wrote:
> Hi G,
>
> sounds great.
>
> How would you use the indentation in
>
> Somesoftware::Mariadb:: ...
>
> The same position as the require? Or two characters on the right? I'm
> asking because resources can be already indented (e.g. two chars) and
> the second line then starts at position 1 on the new line.
>
> I'm still wondering when to use the Backslash. On some sources (e.g.
> http://stackoverflow.com/questions/11406234/puppet-how-can-i-wrap-a-command-into-two-line-if-80-characters
> ) it's recommended but it didn't work on my machine.
>
>
> Am Dienstag, 17. November 2015 20:35:49 UTC+1 schrieb Garrett Honeycutt:
>
> On 11/17/15 11:08 AM, tobias...@gmail.com <javascript:> - tracked
> <https://github.com/puppetlabs/puppet/blob/1a557254012447a4f0a2e01eeebaf52c75ab6f80/lib/puppet/module_tool/skeleton/templates/generator/Rakefile#L3> - tracked
> <https://github.com/puppetlabs/puppet/blob/1a557254012447a4f0a2e01eeebaf52c75ab6f80/lib/puppet/module_tool/skeleton/templates/generator/Rakefile#L3>
>
>
> Best regards,
> -g
>
> --
> Garrett Honeycutt
> @learnpuppet
> Puppet Training with LearnPuppet.com
> Mobile: +1.206.414.8658
>

Hi Tobias,

Backslash does not work with puppet manifests. There is not a way to
wrap to the next line.

Seems my example got lost in formatting. Here's a link.

http://pastebin.com/26eSAJBu

jcbollinger

unread,
Nov 18, 2015, 8:54:02 AM11/18/15
to Puppet Users


On Tuesday, November 17, 2015 at 10:08:34 AM UTC-6, tobias...@gmail.com wrote:
Hi,

I got a file resource

  file {'/usr/java/jboss-as/server/somesoftware/deploy/jontram-ds.xml':
    ensure  => file,
    owner   => 'root',
    group   => 'root',
    mode    => '0655',
    content => template('somesoftware/jboss/jontram-ds.xml.erb'),
    require => [ Class['somesoftware::cpfiles'], somesoftware::mariadb::createdb [ $db_name ] ],
  }

The second last line is obviously to long (over 80 lines). It works in one line but I get a puppet-lint error. I would like to cut it it two. My first thought was to use the '\'

like
    require => [ Class['somesoftware::cpfiles'],\
somesoftware::mariadb::createdb [ $db_name ]
  }



Have you tried omitting the '\'?  As far as I know, Puppet has no requirement that array literals be expressed all on one line, and newlines are permitted as part of the optional whitespace between elements.


John

tobias...@gmail.com

unread,
Nov 18, 2015, 11:42:21 AM11/18/15
to Puppet Users

Have you tried omitting the '\'?  As far as I know, Puppet has no requirement that array literals be expressed all on one line, and newlines are permitted as part of the optional whitespace between elements.
It will work without the "\". I was just wondering why because I haven't found anything in the official documentation and on several web places for some reason the "\" solution was propagated.
Message has been deleted

Peter Huene

unread,
Nov 18, 2015, 11:55:39 AM11/18/15
to puppet...@googlegroups.com
On Wed, Nov 18, 2015 at 8:42 AM, <tobias...@gmail.com> wrote:

Have you tried omitting the '\'?  As far as I know, Puppet has no requirement that array literals be expressed all on one line, and newlines are permitted as part of the optional whitespace between elements.
It will work without the "\". I was just wondering why because I haven't found anything in the official documentation and on several web places for some reason the "\" solution was propagated.

It works because Puppet ignores whitespace between tokens entirely.  That said you can't insert whitespace in the middle of a token and there's no way to "continue" the token into the next line (i.e. a line continuation marker).

For example, this is legal:

```
notice(
   hello::world
)
```

But this is not:

```
notice(
    hello::
    world
)
```

That is because the line break is in the middle of the name token, making it malformed.

Note that string literal tokens may span multiple lines, but the whitespace is made part of the string:

```
notice('
     hello
     world
')
```

i.e. this will print the line breaks as they are part of the string.

Hope that helps.
 

--
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/1491dc4d-91c2-414e-8db8-6f90c3189921%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Henrik Lindberg

unread,
Nov 18, 2015, 6:40:30 PM11/18/15
to puppet...@googlegroups.com
A tip when using the future parser/4.x and you need to have strings with
very wide lines of text:

You can use Puppet heredoc to wrap lines of text over multiple lines in
the source and have them joined in the resulting string. Look at the 'L'
escape option which makes it possible to remove newlines embedded in the
wrapped text.

- henrik

> --
> 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
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/059e205f-f40a-4a58-ad17-cb787cea32a3%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/059e205f-f40a-4a58-ad17-cb787cea32a3%40googlegroups..com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

tobias...@gmail.com

unread,
Nov 19, 2015, 8:29:37 AM11/19/15
to Puppet Users
It works now. Thanks for your informative answers.

Tobias Koeck

unread,
Nov 24, 2015, 7:57:04 AM11/24/15
to puppet...@googlegroups.com
I got the case where the backslash should be used. If you have a string that is too long (> 80 characters) you can solve it by writing

  $watchdog_txt="httpd -f /u1/cust1/www/conf/httpd.conf | /sbin/httpd -f\
/u1/cust1/www/conf/httpd.conf"


On Thu, Nov 19, 2015 at 2:29 PM, <tobias...@gmail.com> wrote:
It works now. Thanks for your informative answers.

--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/7v-N9oHHZh8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/6b3d3567-c290-42ce-83b0-da474ef27c4e%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages