Using selectors and case statements
Although you could write any conditional statement using if
, Puppet provides a couple of extra forms to help you express conditionals more easily: the selector and the case
statement.
How to do it…
Here are some examples of selector and case
statements:
Add the following code to your manifest:
$systemtype = $::operatingsystem ? { 'Ubuntu' => 'debianlike', 'Debian' => 'debianlike', 'RedHat' => 'redhatlike', 'Fedora' => 'redhatlike', 'CentOS' => 'redhatlike', default => 'unknown', } notify { "You have a ${systemtype} system": }
Add the following code to your manifest:
class debianlike { notify { 'Special manifest for Debian-like systems': } } class redhatlike { notify { 'Special manifest for RedHat-like systems': } } case $::operatingsystem { 'Ubuntu', 'Debian': { include debianlike } 'RedHat', 'Fedora', 'CentOS': { include redhatlike } default: { notify { "I don't know what kind of system you have...