On Tue, Jul 3, 2012 at 7:53 AM, llowder@oreillyauto.com
<llowder@oreillyauto.com> wrote:> 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?
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
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.