On 2014-11-07 16:38, Chris Cowley wrote:
OK, so what it the recommended way to do this? Somehow it is not
something I have come up against before, I have the impression that it
is a lot harder than simply:

if $variable {
   do stuff
}

In version before Puppet 4.0.0 the values as boolean map like this:

"falsey":   empty string, false, undef
"truthy":   everything else

In Puppet 4.0.0 this will be:

"falsey":   false, undef
"truthy":   everything else

In Puppet < 4.0.0, an undef is considered to be equal (==) to an empty string. In 4.0.0 this will no longer be the case and only undef is undef when comparing and checking equality.

Thus, if you want to check if a value is undef (but you do not want to match empty strings) you must jump through hoops to do this using something that does not equate undef with "", such as the 'in' operator. (Note that the undefined value must be placed in the array, it cannot appear on the left hand side as this raises an error the left side is not a String (in versions before 4.0.0).

if $x == undef and !("" in [$x])
  # do something, $x is undef and not deliberately set to empty string
end

This will continue to work in 4.0.0 (even if undef and "" are not considered to be the same. (The reason this works is because there are bugs in the implementation of "in" that does not equate undef with "") - that behavior will not be changed.

Regards
- henrik

I've had a look through stdlib and it does not seem to have anything
that helps here (if that is the case, then I will make a feature request).

--
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+unsubscr...@googlegroups.com
<mailto:puppet-users+unsubscr...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/ac5be1c4-073a-404b-969d-14b53267cf7a%40googlegroups.com
<https://groups.google.com/d/msgid/puppet-users/ac5be1c4-073a-404b-969d-14b53267cf7a%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/

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/lpsnrk%245su%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to