help-cfengine
[Top][All Lists]
Advanced

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

Re: Variable substitution in class lists


From: Chris Edillon
Subject: Re: Variable substitution in class lists
Date: Sun, 25 Aug 2002 21:29:25 -0400 (GMT+4)

On Sun, 25 Aug 2002, Kirk Bauer wrote:

> On Sun, 25 Aug 2002 Mark.Burgess@iu.hio.no wrote:
> 
> > This would be very dangerous. And would be difficult to evaluate
> > efficiently, so it is disallowed. Classes are separate to macros.
> > 
> > cfserver in your class is not even a valid class name,
> 
> cfserver expands to the hostname 'cfserver.mydomain.com', which is a
> valid class name, right?  I currently have it working with this:
> 
  nope, dots aren't allowed in class names because they're
parsed as logical ANDs when classes are listed together.

> control:
>    cfserver = ( cfserver.mydomain.com )
> 
> copy:
>    !cfserver.mydomain.com::

this means 'if cfserver isn't defined and both mydomain and
com are defined, do the copy', which doesn't sound like what
you really want.
  looks to me as if you're confusing macros and classes (which
are defined in very similar manners, just in different command
sections).  a macro cannot be used in a class list (bit before
the double colons), and a class cannot be used anywhere but a
class list.  try something like this:

control:
    cfserver = ( cfserver.mydomain.com )

classes:
    cfserver = ( cfserver.mydomain.com )

copy:
    !cfserver::
        /etc/shadow  dest=/etc/shadow
                     mode=600
                     server=${cfserver}
                     encrypt=true
                     verify=true
       
i believe that macros and classes have different namespaces, but
i haven't tested it to be certain (mark?).  yes, that looks strange,
and you're typing the server name twice.  however, say you have
multiple servers and you want your machines to go to a different
one to spread the load.  you could write a module which returns
the name of a server at random, and set a class which contains
all of them to accomplish the same thing:

control:
    actionsequence = ( module:get_cfserver
                       copy
                     )

classes:
    cfservers = ( cfserver1.mydomain.com
                  cfserver2.mydomain.com
                  cfserver3.mydomain.com
                )

copy:
    !cfservers::
        /etc/shadow  dest=/etc/shadow
                     mode=600
                     server=${cfserver}
                     encrypt=true
                     verify=true

the ${cfserver} macro referenced in the copy command would be
defined by module:get_cfserver, a script or program which would
randomly return one of the three servers listed in the cfservers
class.  see 'writing plugin modules' in the tutorial for more
information.

chris





reply via email to

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