Because cfengine works at a very high level, doing very many things for very few lines of code it might seem that some flexibility is lost. When we restrict certain actions to special classes it is occasionally useful to be able to switch off classes temporarily so as to cancel the special actions.
You can define classes of your own which can be switched on and off,
either on the command line or from the action sequence. For example,
suppose we define a class include. We use addclasses
to
do this.
addclasses = ( include othersymbols )
The purpose of this would be to allow certain `excludable actions' to be defined. Actions defined by
any.include:: actions
will normally be carried out, because we have defined include
to
be true using addclasses
. But if cfengine is run in a restricted
mode, in which include
is set to false, we can exclude these
actions.
So, by defining the symbol include
to be false, you can exclude
all of the actions which have include
as a member. There are two
ways in which this can be done, one is to negate a class globally using
cfengine -N include
This undefines the class include
for the entire duration of the
program.
Another way to specify actions is to use a class to select only a subset of all the actions defined in the actionsequence. You do this by adding a class name to one on the actions in action sequence by using a dot `.' to separate the words. In this case the symbol only evaluates to `true' for the duration of the action to which it it attached. Here is an example:
links.onlysome shellcommands.othersymbols.onlysome
In the first case onlysome
is defined to be true while
this instance of links
is executed. That means that only actions
labelled with the class onlysome
will be executed as a result of
that statement. In the latter case, both onlysome
and
othersymbols
are defined to be true for the duration of
shellcommands
.
This syntax would normally be used to omit certain time-consuming actions, such as tidying all home directories. Or perhaps to synchronize certain actions which have to happen in a certain order.
For more advanced uses of cfengine you might want to be able to define a class on the basis of the success or failure of a user-program, a shell command or user script. Consider the following example
groups: have_cc = ( "/bin/test -f /usr/ucb/cc" "/bin/test -f /local/gnu/cc" )
Note that as of version 1.4.0 of cfengine, you may use the word
classes
as an alias for groups
. Whenever cfengine meets
an object in a class list or variable, which is surrounded by either
single, double quotes or reversed quotes, it attempts to execute the
string as a command passed to the Bourne shell. If the resulting command
has return code zero (proper exit) then the class on the left hand side
of the assignment (in this case `have_cc') will be true. If the
command returns any other value (an error number) the result is
false. Since groups are the logical OR of their members (it is
sufficient that one of the members matches the current system), the
class `have_cc' will be defined above if either `/usr/ucb/cc'
or `/local/gnu/cc' exist, or both.
Go to the first, previous, next, last section, table of contents.