help-cfengine
[Top][All Lists]
Advanced

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

Re: editfiles question


From: Jamie Wilkinson
Subject: Re: editfiles question
Date: Thu, 2 Sep 2004 11:43:32 +1000
User-agent: Mutt/1.5.6+20040803i

This one time, at band camp, Josef Wolf wrote:
>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:

It's not perfect.  I have a library that is gathering some dust at the
moment that was designed to abstract away configuration file edits that
should (well, it's a goal) do all the things you wanted; and once that was
done I was planning on hacking in a new section, "config:" to cfengine.
Unfortunately I've not had any time since I started working on it (maybe 2
years ago!) to get it anywhere near useful for production.

I do all these config edits in M4 macros, though, so I say 'set this option
to this value using shell variable syntax', or 'this one uses spaces instead
of equals for the key/val separator'.  Attached is the editfiles.m4 that I
use in my cfengine rollouts.  This solves the problem of repeated typing for
me, but it's not ideal (I can get lost for hours in the M4 if I try to add a
feature...)

This file won't work by itself here, but you can get the idea of the things
it does.

dnl editfiles.m4 -*- m4 -*-
dnl
CF_SECTION(<<editfiles>>)dnl
dnl
define(<<CF_EDITFILES_TAILCHOMP>>, <<patsubst(<<$1>>, << +$>>)>>)dnl
dnl
define(<<CF_REGEX_QUOTE>>, <<patsubst(<<$1>>, <<\(\[\|\]\)>>, <<\\\&>>)>>)dnl
dnl
define(<<CF_EDITFILES_KEYVAL_SEP>>, <<
dnl comment the output, whoa
# set '$1' to '$3'
dnl remove trailing whitespace when looking for the line
BeginGroupIfNoLineMatching 
<<'^>>CF_REGEX_QUOTE(CF_EDITFILES_TAILCHOMP($1$2))<<.*'>>
  dnl append the key and separator to the end of file
  Append <<'>>CF_EDITFILES_TAILCHOMP($1$2)<<'>>
EndGroup
dnl back to the beginning of the file for the next search
ResetSearch "1"
LocateLineMatching <<'^>>CF_REGEX_QUOTE(CF_EDITFILES_TAILCHOMP($1$2))<<.*'>>
BeginGroupIfNoMatch <<'^>><<CF_REGEX_QUOTE(<<$1$2$3>>)>><<$'>>
  dnl replace the line if it doesn't look the way it should
  ReplaceLineWith '<<$1$2$3>>'
EndGroup
dnl back to the beginning for the next search
ResetSearch "1">>)dnl
dnl
define(<<CF_EDITFILES_KEYVAL_EQUALS>>, <<CF_EDITFILES_KEYVAL_SEP($1, << = >>, 
$2)>>)dnl
define(<<CF_EDITFILES_KEYVAL_COLON>>, <<CF_EDITFILES_KEYVAL_SEP($1, <<: >>, 
$2)>>)dnl
define(<<CF_EDITFILES_KEYVAL_SPACE>>, <<CF_EDITFILES_KEYVAL_SEP($1, << >>, 
$2)>>)dnl
define(<<CF_EDITFILES_KEYVAL_SHELL>>, <<CF_EDITFILES_KEYVAL_SEP(<<$1>>, <<=>>, 
<<$2>>)>>)dnl
dnl
dnl
dnl Special macro for defining an interface
define(<<CF_EDITFILES_RH_INTERFACE>>, <<dnl
CF_EDIT_FILE(/etc/sysconfig/network-scripts/ifcfg-$1,
CF_EDITFILES_KEYVAL_SEP(DEVICE, =, $1)
CF_EDITFILES_KEYVAL_SEP(BOOTPROTO, =, static)
CF_EDITFILES_KEYVAL_SEP(ONBOOT, =, yes)
CF_EDITFILES_KEYVAL_SEP(IPADDR, =, $2)
CF_EDITFILES_KEYVAL_SEP(NETMASK, =, $3)

# /etc/sysconfig/network has the gateway
DeleteLinesMatching '^GATEWAY=.*$',
patsubst($1, <<:.+>>)<<>>_restart,
ifelse($4, <<>>, <<>>, $4))>>)dnl CF_EDITFILES_RH_INTERFACE
dnl
define(<<CF_EDITFILES_DEB_INTERFACE>>, <<>>)dnl
dnl
define(<<CF_EDIT_FILE>>, <<
ifelse($4, <<>>, <<>>, <<# $4
>>)dnl
{ $1
# Don't make a backup file.
Backup "off"
# Create the file if it doesn't exist.
AutoCreate
# Tell us about it
Inform "on"
$2
ifelse($3, <<>>, <<>>, <<
# if the file has changed define some classes
DefineClasses "$3"
>>)dnl ifelse
}>>)dnl CF_EDIT_FILE

-- 
jaq@spacepants.org                           http://spacepants.org/jaq.gpg



reply via email to

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