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