Conditional statement examples
On this page:
if statement, using expressions and facts
An if statement, whose conditions are expressions that use facts
provided by the agent.
Copy
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.
Copy
if 'www' in $hostname {
...
}
For details about if statements, see Conditional statements and expressions.
Case statement
A case statement.
Copy
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.
Copy
$rootgroup = $osfamily ? {
'RedHat' => 'wheel',
/(Debian|Ubuntu)/ => 'wheel',
default => 'root',
}
For details about selector statements, see Conditional statements and expressions.