help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: activating a class from shellcommands


From: Chris Edillon
Subject: Re: activating a class from shellcommands
Date: Tue, 5 Nov 2002 23:07:26 -0400 (GMT+4)

On Tue, 5 Nov 2002, Wheeler, John wrote:

> It appears that my script "checksw2" which I'd like to pass all classes to
> using $(allclasses) is actually getting the class in the define statement.
> My guess is that if the script successeds it activates the class. I couldn't
> find where this behavior is defined. 

  when cfagent executes a shellcommand or a module (see below),
it passes in the environment variable $CFALLCLASSES.  this is
a colon-separated list of all currently defined classes, which
you can split out and use as you need in a script.  however...

> Can somone help me solve this? Is what I'm trying to do, set a class based
> on the return value of a script in shellcomands, possible?
> 
  sounds like what you actually want is a module.  cfengine
allows for user-defined plugin modules which can be used to
define variables and classes based on arbitrary tests.  a
module is an external script/program which has a certain
output format which cfengine uses to define classes and
variables.  read the "writing plugin modules" section of
the cfengine tutorials for details, but here's a quick
example:

    #!/bin/sh
    #
    # redhat linux boxes will set up host-based packet filtering
    # using ipchains or iptables if either an "ipchains" or "iptables"
    # setup file exists in /etc/sysconfig
    #
    if [ ! -f /etc/redhat-release ]; then exit 0; fi
    if [ -n /etc/sysconfig/ipchains -o -/etc/sysconfig/iptables ]
    then
        echo "+is_filtering"
    fi

this would define a class called "is_filtering" if either ipchains
or iptables is set up on the machine.  you'd have to name the above
script something like "module:filtercheck" and place it in the
modules directory (defined in the control: section).  you'd then
make it an early part of the action sequence so that your class
would be defined before you had to use it, and you'd have to put
the class name in the AddInstallables control variable so that
cfengine would know that it's a class which may be defined on
the fly:

    control:
        moduledirectory = ( /etc/cfengine/modules )
        AddInstallables = ( is_filtering )
        actionsequence  = ( module:filtercheck
                            ...
                          )

again, the cfengine tutorial convers this in greater detail.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]