classesmatching
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 unanchored 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
unanchored regular expressions are returned. Class tags are set
using the meta
attribute.
Example:
body common control
{
bundlesequence => { run };
}
bundle agent run
{
vars:
"all" slist => classesmatching(".*");
"c" slist => classesmatching("cfengine");
"c_plus_plus" slist => classesmatching("cfengine", "plus");
# order of classes is not guaranteed
"internal_environment_unsorted" slist =>
classesmatching(".*", 'cfe_internal', 'source=environment');
"internal_environment" slist =>
sort(internal_environment_unsorted, 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)'";
"All classes with the 'cfe_internal' and 'source=environment' tags = '$(internal_environment)'";
"Classes matching 'cfengine' = '$(c)'";
# this should produce no output
"Classes matching 'cfengine' with the 'plus' tag = $(c_plus_plus)";
}
Output:
R: All classes with the 'cfe_internal' and 'source=environment' tags = '_cfe_output_testing'
R: All classes with the 'cfe_internal' and 'source=environment' tags = 'agent'
R: All classes with the 'cfe_internal' and 'source=environment' tags = 'opt_dry_run'
R: Classes matching 'cfengine' = 'cfengine'
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