Puppet supports some common comparison operators, which resolve to true or false:
==
, returns true if the operands are equal. Used with numbers, strings, arrays, hashes, and Booleans. For example:if $::osfamily == 'Debian' { [ ... ] }
!=
, returns true if the operands are different:if $::kernel != 'Linux' { [ ... ] }
<
, 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 { [ ... ] }
=~
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./ { [ ... ] }
!~
, opposite to =~
, resolves false if the operands match.