Comparison operators
Puppet supports some common comparison operators, which resolve to true or false:
- Equal
==
, returns true if the operands are equal. Used with numbers, strings, arrays, hashes, and Booleans. For example:if $::osfamily == 'Debian' { [ ... ] }
- Not equal
!=
, returns true if the operands are different:if $::kernel != 'Linux' { [ ... ] }
- Less than
<
, greater than>
, less than or equal to<=
, and greater than or equal to>=
can be used to compare numbers:if $::uptime_days > 365 { [ ... ] } if $::operatingsystemrelease <= 6 { [ ... ] }
- Regex match
=~
compares a string (left operator) with a regular expression (right operator), and resolves true, if it matches. Regular expressions are enclosed between forward slashes and follow the normal Ruby syntax:if $mode =~ /(server|client)/ { [ ... ] } if $::ipaddress =~ /^10\./ { [ ... ] }
- Regex not match
!~
, opposite to=~
, resolves false if the operands match.