Conditional statement examples
if statement, using expressions and facts
An if
statement, whose conditions are expressions that use facts
provided by the agent.
if $is_virtual { warning( 'Tried to include class ntp on virtual machine; this node might be misclassified.' ) } elsif $operatingsystem == 'Darwin' { warning( 'This NTP module does not yet work on our Mac laptops.' ) else { include ntp }
For details about if
statements, see Conditional statements and expressions.
if statement, with in expression
An if
statement using an in
expression.
if 'www' in $hostname { ... }
For details about if
statements, see Conditional statements and expressions.
Case statement
A case statement.
case $operatingsystem { 'RedHat', 'CentOS': { include role::redhat } /^(Debian|Ubuntu)$/:{ include role::debian } default: { include role::generic } }
For details about case statements, see Conditional statements and expressions.
Selector statement
A selector statement being used to set the value of the $rootgroup
variable.
$rootgroup = $osfamily ? { 'RedHat' => 'wheel', /(Debian|Ubuntu)/ => 'wheel', default => 'root', }
For details about selector statements, see Conditional statements and expressions.