variablesmatching

Table of Contents

Prototype: variablesmatching(name, tag1, tag2, ...)

Return type: slist

Description: Return the list of variables matching name and any tags given. Both name and tags are regular expressions.

This function searches for the given anchored name and tag1, tag2, ... regular expressions in the list of currently defined variables.

When one or more tags are given, the variables with tags matching any of the given anchored regular expressions are returned (logical OR semantics). For example, if one variable has tag inventory, a second variable has tag time_based but not inventory, both are returned by variablesmatching(".*", "inventory", "time_based"). If you want logical AND semantics instead, you can make two calls to the function with one tag in each call and use the intersection function on the return values.

Variable tags are set using the meta attribute.

Example:

body common control
{
      bundlesequence => { run };
}

bundle agent run
{
  vars:
      "all" slist => variablesmatching(".*");
      "v" slist => variablesmatching("default:sys.cf_version.*");
  reports:
      "Variables matching 'default:sys.cf_version.*' = $(v)";
}

Output:

R: Variables matching 'default:sys.cf_version.*' = default:sys.cf_version_major
R: Variables matching 'default:sys.cf_version.*' = default:sys.cf_version_patch
R: Variables matching 'default:sys.cf_version.*' = default:sys.cf_version
R: Variables matching 'default:sys.cf_version.*' = default:sys.cf_version_minor

History: Introduced in CFEngine 3.6