help-cfengine
[Top][All Lists]
Advanced

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

Réf. : RE: activating a class from shellcommands


From: paguerlais
Subject: Réf. : RE: activating a class from shellcommands
Date: Wed, 6 Nov 2002 09:29:16 +0100

You can activate a module depending on classes, by "computing" your
actionsequence :

control:
      actionsequence = ( copy )

      my_class1::
            actionsequence = ( module:my_module param_for_class1 )
      my_class2::
            actionsequence = ( module:my_module param_for_class_2 )

      any::
            actionsequence = ( files )

The actionsequence "variable" is a special "accumulative" variable : its
value isn't the right-value of the equal sign, but this right value is
added at the end of the current value of actionsequence. It can be
surprising (mainly because of the equal sign which acts differently of what
we are used to) but it is very useful.
Therefore, in my previous example, if my_class1 is defined, actionsequence
will be : ( copy "module:my_module param_for_class_1" files ).

Patrice





help-cfengine-admin@gnu.org@us.britannica.com> le 06/11/2002 05:25:33

Envoyé par :      "Wheeler, John" <JWheeler@us.britannica.com>


Pour : 'Chris Edillon' <jce@zot.com>, "Wheeler, John"
       <JWheeler@us.britannica.com>
cc :   "'help-cfengine@gnu.org'" <help-cfengine@gnu.org>

Objet :     RE: activating a class from shellcommands




yep, went through this scenerio with the solution I'm trying to impliment.
A module will solve my problem, but I want a shell command because I want
to be able to invoke the shell command based on a class. I could embed the
logic of verifing which class is active in the module, but that wouldn't be
very cfengine like ;)

I found another possible solution was to have the script read an
environment variable. The issue with this is that I use cfexecd run out of
init to startup cfagent, so I can't pass cfagent any command line params. :
(

I've resorted to a less elegant solution that requires two passes of
cfagent to perform my task, software distribution.

Thanks for your help. Speaking of modules, the one I was going to use
always seem to run twice. Anyone else seen this? version 2.0.3 solaris 2.8

wheeler

-----Original Message-----
From: Chris Edillon [mailto:jce@zot.com]
Sent: Tuesday, November 05, 2002 9:07 PM
To: Wheeler, John
Cc: 'help-cfengine@gnu.org'
Subject: Re: activating a class from shellcommands

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.







----------------
Les donnees et renseignements contenus dans ce message sont personnels, 
confidentiels et secrets. Ce message est adresse a l'individu ou l'entite dont 
les coordonnees figurent ci-dessus. Si vous n'etes pas le bon destinataire, 
nous vous demandons de ne pas lire, copier, utiliser ou divulguer cette 
communication. Nous vous prions de notifier cette erreur a l'expediteur et 
d'effacer immediatement cette communication de votre systeme.
The information contained in this message is privileged, confidential, and 
protected from disclosure. This message is intended for the individual or 
entity adressed herein. If you are not the intended recipient, please do not 
read, copy, use or disclose this communication to others; also please notify 
the sender by replying to this message, and then delete it from your system.





reply via email to

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