Style Guide question

20 views
Skip to first unread message

llo...@oreillyauto.com

unread,
Jul 3, 2012, 10:53:21 AM7/3/12
to puppet...@googlegroups.com
Is there an ETA for getting the Style Guide up to date for 2.7.x or even 3.X?

Currently it is geared towards the 2.6.X line, and says that certain things should not be done due to 2.6.x compatibility issues.

For example, it says to use this:
    class ntp(
      $server = 'UNSET'
    ) {

      include ntp::params

      $server_real = $server ? {
        'UNSET' => $::ntp::params::server,
        default => $server,
      }

      notify { 'ntp':
        message => "server=[$server_real]",
      }

    }

and not:

class ntp( $server = $ntp::params::server ) inherits ntp::params { notify { 'ntp': message => "server=[$server]", } }

Now to me, the second one is much easier to read.

Is the fact that the second one won't work in 2.6.x the ONLY reason not to do something like that?



Nan Liu

unread,
Jul 3, 2012, 11:59:24 AM7/3/12
to puppet...@googlegroups.com
TLDR; unless you need to know someone provided an undef value, you
don't need this pattern.

The second example you provided should work with 2.6.x. The 'UNSET'
pattern is typically used to differentiate between user provided undef
and a variable that's undefined.

Here's a horribly contrived example. Source and template are exclusive
for file, and I would like to use source if it's specified, set source
to undef if user provides content, and specify a default source value
if the user doesn't provide source or content:

define myfile (
$source,
$content ) {

if $source {
$mysource = $source
} elsif $content {
$mysource = undef
} else {
$mysource = "puppet:///modules/${caller_module_name}/${name}"
}
...
}

However if the user ever supplied:

myfile { 'serv.conf':
content => undef,
}

I have no way to test if the user provided undef using the first
example and it will use my default source instead. I have to do
something pretty hideous:

define myfile (
source,
content = 'UNSET' ) {
if $source {
$mysource = $source
} elsif $content =='UNSET' {
$mysource = "puppet:///modules/${caller_module_name}/${name}"
} else {
$mysource = undef
}
...
}

I cringe when I see it, but I understand the problem it's trying to solve.

HTH,

Nan
Reply all
Reply to author
Forward
0 new messages