Using selectors and case statements

"Smarts is the most exclusive club in town. Everyone welcome."—Sign

Sometimes it's important to be selective. Although you could write any conditional statement using if, Puppet provides a couple of extra forms to help you express conditionals more easily such as the selector and the case statement.

How to do it…

  1. Add the following to your manifest:
    $systemtype = $operatingsystem ? {
        "Ubuntu" => "debianlike",
        "Debian" => "debianlike",
        "RedHat" => "redhatlike",
        "Fedora" => "redhatlike",
        "CentOS" => "redhatlike",
        default  => "redhatlike",
    }
    notify { "You have a ${systemtype} system": }
  2. Next, add the following to your manifest:
    class debianlike { notify { "Special manifest for Debian-like systems": } } class redhatlike ...

Get Puppet 2.7 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.