Conditional statements
Puppet has the conditional statements you would expect of any language, with if
, unless
, and case
allowing code behavior to be different depending on things such as facts or data from external sources. Puppet additionally uses selectors, which are similar to a case
statement but return a value instead of executing code on result.
If and unless statements
The if
statement follows a specific syntax that includes the if
keyword followed by a condition, an opening curly brace ({
), the Puppet code to execute if the condition evaluates to true
, and a closing curly brace (}
).
The following example is a simple check on a Boolean in example_bool
to print a notice if it contains true
:
if $example_bool { notice 'It was true' }
This can be optionally extended by adding an else
keyword after the closing curly brace (}
) of the if
statement and then using an opening curly brace ({
) with Puppet code to perform if the condition is false
. This...