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.

This function behaves exactly like variablesmatching_as_data() but returns just the list of all the variables. If you want their contents as well, see that function.

Example:

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

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

Output:

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

See also: classesmatching(), bundlesmatching(), variablesmatching_as_data()

History: Introduced in CFEngine 3.6