A quick rundown of what we've learned in this chapter.
You can conditionally apply a block of Puppet code using an if
statement:
if EXPRESSION { OPTIONAL_SOMETHING }
You can add extra elsif
clauses and an optional else
clause:
if EXPRESSION { OPTIONAL_SOMETHING } elsif ANOTHER_EXPRESSION { OPTIONAL_SOMETHING_ELSE } else { OPTIONAL_OTHER_THING }
The else
clause, if present, will be applied if none of the conditions match.
The case
statement lets you conditionally apply code if any of a number of possible cases are matched:
case EXPRESSION { CASE1 { BLOCK1 } CASE2 { BLOCK2 } CASE3 { BLOCK3 } ... default : { ... } }
With a selector
, you can test a number of cases and return a value:
$result = EXPRESSION ? { CASE1 => VALUE1, CASE2 => VALUE2, CASE3 => VALUE3, default => DEFAULT_VALUE, }