Table of Contents

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.


bundle agent main
        meta => { "plus", "defined_from=$(this.bundle)" };
        meta => { "plus", "defined_from=$(this.bundle)" };

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

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

      # 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)";


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()

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

History: Introduced in CFEngine 3.6