[Top][All Lists]

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

Re: Loops in cfengine?

From: Luke A. Kanies
Subject: Re: Loops in cfengine?
Date: Thu, 23 Jan 2003 09:55:13 -0600 (CST)

On Thu, 23 Jan 2003, Florian Thiel wrote:

> Hi there!
> Is there an notion of loops in cfengine (couldn't find any by browsing
> the docs)? I need to do stuff depending on, say, the number of network
> interfaces in a machine. For each card I need to add an entry to a file.
> Do I have to do this with a simple script or can cfengine help me?

Cfengine kind of has iteration, but it's very limited (too limited, in my
mind).  You can assign multiple values to a variable, separated by the
'Split' character, and any shellcommand you call with that variable will
be called iteratively.  There are a couple other places this is used (I'd
like to see it everywhere, or just generic support for lists), but
shellcommands is what you're looking for.

I think if you look for "iteration" in the reference page, you'll find the

> If I have to do it with a script, how can cfengine then detect changes
> in the file and rerun the script? I could overwrite it on every cf-run,
> but then I would also have to reload all services etc...

I have looked into this quite a bit.  Write a module, pass the values to
the module, and it is up to the module to decide if it should overwrite or
do nothing.  I recommend md5 sums or something like that; specifics depend
on what exactly you are trying to do.

If you are creating a single file based on the number of interfaces, then
cfengine can't really md5 the output of ifconfig -a (which not all
platforms even have *cough*HP-UX*cough*), so it would be up to your module
to decide if it were appropriate to rewrite the file or not, depending on
research it performs, maybe running ifconfig -a or checking for new
/etc/hostname.* files.

I've basically found that most things I want to do in cfengine will
require me to write an external module, which I find disappointing because
cfengine doesn't seem that excited at integrating with modules.  For
instance, you can't pass the state of all variables to a module, as far as
I know, which is a pretty serious limitation.

Is that what you were looking for?

It is odd, but on the infrequent occasions when I have been called upon
in a formal place to play the bongo drums, the introducer never seems to
find it necessary to mention that I also do theoretical physics.
                -- Richard Feynman

reply via email to

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