It's useful to be able to do different things in a manifest depending on the value of some variable or expression. Puppet provides several ways to do this. The first is the if
statement.
An if
statement has the
following form:
if EXPRESSION { OPTIONAL_SOMETHING }
The part of the manifest represented by OPTIONAL_SOMETHING
will only be applied if the value of EXPRESSION
is true. We'll learn more about expressions later in the chapter, but for now let's take a simple example:
if $eggs == 61 { notify { 'Glory be, eggs have just gone up to 61¢ a dozen!': } }
Here the EXPRESSION
is:
$eggs == 61
The ==
operator means "is equal to".
Note
Note the difference between $eggs == 61
and $eggs = 61
$eggs = 61
has a different meaning to Puppet. The single =
operator has the effect of assigning the value 61
to the variable $eggs, while the double ==
operator tests equality. So in conditional expressions—expressions in an if
statement, for example—we always use ==
, not =
.
Puppet reads...