Cfengine configuration directory

User defined modules

Relevant classes: any

The functionality of the actionsequence can be extended using modules. A module is defined in the cfengine program like this:
control:

 moduledirectory = ( /directory/modules )

 actionsequence = ( module:testmod shellcommands )

Or

 control:

   moduledirectory = ( /local/cfengine/modules )
 
   actionsequence = ( 
                    files 
                    module:myplugin.specialclass 
                    "module:argplugin.specialclass arg1 arg2"
                    copy 
                    )
 ...
The module may be written in any language. A simple protocol is used to communicate class data back from the module. Any lines beginning with a "+" define new classes. Any lines beginnning with a "-" negate already defined classes. Lines beginning with "=" are used to define variables. Variable definition will not work prior to version 1.6.0, since variables are expanded before modules are run.
#!/bin/csh

echo "=MYVAR=my test string"
echo "+newclass"
echo "-removeclass"

echo "argvv is $argv"

When the module is called, it receives a list of arguments , e.g. try
#
# cfengine.conf
#

control:

 moduledirectory = ( /tmp )

 fish = ( antifish )
 arg1 = ( "$(fish) is not a fish on " )

 actionsequence = ( 
                  "module:testenv.class1.class2 $(arg1) arg2"
                  shellcommands 
                  )

 shellcommands:

   "/bin/echo the date is and $(MYVAR)"




#!/bin/sh
#
# File module:testenv
# echo arguments

echo $*

#Set a cfengine variable
echo "=MYVAR=somestring"

echo End of module
and inherits an environment variable CFALLCLASSES which contains a list of active classes. This may be decoded like this:
#!/usr/bin/perl

print "Decoding $ENV{CFALLCLASSES}\n";

@allclasses = split (":","$ENV{CFALLCLASSES}");

while ($c=shift(@allclasses))
   {
   $def{$c} = 1;
   print "$c is set\n";
   }

if ($def{"solaris"})
   {
   print "This is a solaris host\n";
   }

Back to documentation