In CFEngine classes are used for decision making. Classes can be defined as the result of a promise by attaching a classes body to the promise via the /classes/ attribute.
For example, here we run the command
echo Hello World and define bundle
scoped classes using the results classes body prefixed with
Note in the policy output, we see Hello_World_repaired and Hello_World_reached are defined.
notice: Q: "...echo Hello Worl": Hello World R: Defined Classes: Hello_World_repaired, Hello_World_reached
Sometimes people ask:
Can I automatically define classes for every promise?
This is possible since CFEngine 3.9.0 introduced the concept of default bodies.
Default bodies allow the definition of bodies in the bodydefault namespace
that will be used with a promise any time a promise does not specify a body of
that type. For example, we can define
body classes commands_classes that will
be used for any commands promise that does not specify a specific classes body.
This results in the
commands_classes body being attached to any commands
promise which does not use an explicit classes body.
Here is the policy output. We can see that the commands promise to echo Hello
resulted in the definition of
command_echo_hello_reached because it used
body classes commands_classes
(the default classes body for commands promises).
notice: Q: "...echo Hello": Hello notice: Q: "...echo GoodBye": GoodBye R: command_echo_hello_repaired R: GoodBye_repaired R: command_echo_hello_reached R: GoodBye_reached