Booleans
Booleans are one-bit values, representing true or false. The condition of an if
statement expects an expression that resolves to a Boolean
value. All of Puppet's comparison operators resolve to Boolean
values, as do many functions.
The Boolean data type has two possible values: true
and false
. Literal Booleans must be one of these two bare words
(that is, not in quotation marks).
Automatic conversion to Boolean
- The
undef
value is converted to Booleanfalse
. - All other values are converted to Boolean
true
.
Notably, this means the string values ""
(a
zero-length string) and "false"
(in quotation
marks) both resolve to true
.
To convert values to Booleans with more permissive rules (for example, 0
to false
, or "false"
to false
), use the
str2bool
and num2bool
functions in the puppetlabs-stdlib
module.
The Boolean
data type
The data type of Boolean values is Boolean
.
It matches only the values true
or false
.
It can accept parameters of either [true]
or [false]
to restrict accepted data to the parameter-specified
value. For example: Boolean[true] $b
You can use abstract types to match values that might be Boolean or might have some
other value. For example, Optional[Boolean]
matches
true
, false
, or
undef
. Variant[Boolean,
Enum["true", "false"]]
matches stringified Booleans as well as true
Booleans.