Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.
smcclellan edited this page Jul 11, 2019 · 16 revisions

A tag consists of a unique name and a rule. The tag matches a node if evaluating it against the tag's facts results in true. Note that tag matching is case sensitive.

As an example, here is a tag rule:

["or",
 ["=", ["fact", "macaddress"], "de:ea:db:ee:f0:00"]
 ["=", ["fact", "macaddress"], "de:ea:db:ee:f0:01"]]

which could also be written as

["in", ["fact", "macaddress"], "de:ea:db:ee:f0:00", "de:ea:db:ee:f0:01"]

The syntax for rule expressions is defined in lib/razor/matcher.rb. Expressions are of the form [op arg1 arg2 .. argn] where op is one of the operators below, and arg1 through argn are the arguments for the operator. If they are expressions themselves, they will be evaluated before op is evaluated.

The expression language currently supports the following operators:

Operator Returns Aliases
["=", arg1, arg2] true if arg1 and arg2 are equal (case-sensitive for strings) "eq"
["!=", arg1, arg2] true if arg1 and arg2 are not equal (case-sensitive for strings) "neq"
["like", arg1, arg2] true if arg1 (string) matches the regular expression generated from arg2 (string) (Coming soon)
["and", arg1, ..., argn] true if all arguments are true
["or", arg1, ..., argn] true if any argument is true
["not", arg] logical negation of arg, where any value other than false and nil is considered true
["fact", arg1 (, arg2)] the fact named arg1 for the current node
["metadata", arg1 (, arg2)] the metadata entry arg1 for the current node (error if returns array/hash)
["tag", arg] the result (a boolean) of evaluating the tag with name arg against the current node
["in", arg1, arg2, ..., argn] true if arg1 equals one of arg2 .. argn
["num", arg1] arg1 as a numeric value, or raises an error
["str", arg1] arg1 as a string value (Coming soon)
[">", arg1, arg2] true if arg1 is strictly greater than arg2 "gt"
["<", arg1, arg2] true if arg1 is strictly less than arg2 "lt"
[">=", arg1, arg2] true if arg1 is greater than or equal to arg2 "gte"
["<=", arg1, arg2] true if arg1 is less than or equal to arg2 "lte"
["lower", arg1]
(Pending for 0.15.0)
the result (a string) of converting the string in arg1 to lower case
["upper", arg1]
(Pending for 0.15.0)
the result (a string) of converting the string in arg1 to upper case

Note that the fact and metadata operators take an optional second argument. If arg2 is passed, it is returned if the fact/metadata entry arg1 is not found. If the fact/metadata entry arg1 is not found and no second argument is given, a RuleEvaluationError is raised.

Note about Razor 1.9.6 and above: The fact and metadata operators also support scoping into hash and array data structures using a dot-syntax. ["fact", "processors.count"] will return the value for the key count inside the processors hash. For arrays, an index can be used: ["fact", "processors.models.0"] will return the first entry inside the models array inside the processors hash. ["fact", "processors.models.length"] will return the length of the models array.

Clone this wiki locally