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

Return type: slist

Description: Return the list of set classes matching name and any tags given. Both name and tags are regular expressions. name is required, tags are optional.

This function searches for the given anchored name and optionally tag1, tag2, ... regular expression in the list of currently set classes. The search order is hard, soft, then local to the current bundle.

When any tags are given, only the classes with those tags matching the given anchored regular expressions are returned. Class tags are set using the meta attribute.

Example:

code
bundle agent main
{
  classes:
      "example_one";
      "example_two"
        meta => { "plus", "defined_from=$(this.bundle)" };
      "example_three"
        meta => { "plus", "defined_from=$(this.bundle)" };

  vars:
      "cfengine_classes"
        slist => sort( classesmatching("cfengine"), lex);

      "example_with_plus"
        slist => sort( classesmatching("example.*", "plus"), lex);

  reports:
      # you may find this list of all classes interesting but it
      # produces different output every time, so it's commented out here
      # "All classes = '$(all)'";

      "Classes matching 'cfengine' = '$(cfengine_classes)'";

      # this should produce no output
      "Classes matching 'example.*' with the 'plus' tag = $(example_with_plus)";
}

Output:

code
R: Classes matching 'cfengine' = 'cfengine'
R: Classes matching 'example.*' with the 'plus' tag = example_three
R: Classes matching 'example.*' with the 'plus' tag = example_two

See also: variablesmatching(), bundlesmatching(), classes defined via augments, classmatch(), countclassesmatching()

Note: This function replaces the allclasses.txt static file available in older versions of CFEngine.

History: Introduced in CFEngine 3.6