variablesmatching_as_data

Table of Contents

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

Return type: data

Description: Return a data container with the map of variables matching name and any tags given to the variable contents. 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_as_data(".*", "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() but returns a data container with the full contents of all the variables instead of just their names.

Example:

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

bundle agent run
{
  vars:
      "all" data       => variablesmatching_as_data(".*"); # this is huge
      "v" data         => variablesmatching_as_data("default:sys.cf_version_major.*");
      "v_dump" string => format("%S", v);
  reports:
      "Variables matching 'default:sys.cf_version.*' = $(v_dump)";
}

Output:

R: Variables matching 'default:sys.cf_version.*' = {"default:sys.cf_version_major":"3"}

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

History: Introduced in CFEngine 3.10