Testing whether values are contained in strings

Want to know what's in and what's out? Puppet's in keyword can help, with expressions such as the following:

if "foo" in $bar

This will be evaluated as true if the string foo is a substring of $bar. If $bar is an array, and if foo is an element of the array, the expression is true. If $bar is a hash, the expression is true if foo is one of the keys of $bar.

How to do it…

  1. Add the following code to your manifest:
    if $operatingsystem in [ "Ubuntu", "Debian" ] {
        notify { "Debian-type operating system detected": }
    } elsif $operatingsystem in [ "RedHat", "Fedora", "SuSE", "CentOS" ] {
        notify { "RedHat-type operating system detected": }
    } else {
        notify { "Some other operating system detected": }
    }
  2. Run Puppet: ...

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.