help-cfengine
[Top][All Lists]
Advanced

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

Re: editfiles question


From: Josef Wolf
Subject: Re: editfiles question
Date: Wed, 1 Sep 2004 22:27:09 +0200
User-agent: Mutt/1.4.1i

On Wed, Sep 01, 2004 at 12:05:47AM +1000, Jamie Wilkinson wrote:

> http://shipyard.com.au/shipyard/articles/sysadmin/cfengine-configfiles.py

Ahhh, nice link!  Thanks for pointing out some very important aspects!
But I still see some flaws with this solution:

- The regexes check only for "canonical" formats without ensuring that
  the keywords already _are_ canonical.  For example: what happens when
  a keyword has leading whitespace?  In this case the matches will fail
  and a second configuration line with the given keyword will be added.
  The solution would be to prepend the block with something equivalent
  to perl's

      s/^\s*(Keyword)\b((\s)\s*(\S.*))?/$1 $3/  # Make line canonical

  expression.  But I can't figure out how this can be done in cfengine
  language.  Any hints?

- The regexes don't check for word-boundaries at the end of the keywords.
  What happens when new keywords are introduced which start with an existing
  keyword?  For example: what happens when ssh decides to introduce a
  new X11ForwardingFooBar keyword?
  I suppose this can be fixed by using '^X11Forwarding\>.*'.  Can somebody
  confirm this?

- The blocks are almost identical for X11Forward, Protocol, SyslogFacility
  etc/pp.  It would be nice to have some sort of "subroutine".  Quoting
  from the cfengine-Reference info page:

     If you find yourself writing a lot, you are probably not going about
     things in the right way.

  Nice saying...  But there seem to be some aspects in the language that
  enforce lots of typing.  Even worse: if you want to make identical
  operations to several files (e.g. ssh_config _and_ sshd_config) you
  need to duplicate the already duplicated blocks.

- In every block the keyword that is to be matched is repeated five times.
  This makes a lot of chances for typos.

- How to edit files with a given structure (.INI files or some such.)?

The conclusion seems to be that cfengine is not very good prepared for
editing operations.

Given following block from the example:

      BeginGroupIfNoLineMatching '^X11Forwarding\>.*'
        Append 'X11Forwarding'
      EndGroup
      ResetSearch 1
      LocateLineMatching  '^X11Forwarding\>.*'
      BeginGroupIfNoMatch '^X11Forwarding no$'
        ReplaceLineWith    'X11Forwarding no'
      EndGroup
      ResetSearch 1

Assuming you have the whole file in a multi-line-string, that could be
done (in a more robust way, see above) in perl with:

      unless ( s/^\s*(X11Forwarding)\b.*$/$1 no/mi ) {
        s/\z/X11Forwarding no\n//;
      }

-- 
Please visit and sign and http://www.ffii.org
-- Josef Wolf -- jw@raven.inka.de --



reply via email to

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