This one time, at band camp, Tony Green wrote:
>I'm wading back into cfengine after a bit of a break and I'm running into the same 
>problems, hopefully one of the cfengine advocates out there will be able point me in 
>the right direction.
>
>A typical example is:
>
>I'm editing /etc/system on solaris, I want to ensure that this line is
>set :
>set shmsys:shminfo_shmmax=4294967296
>
>I can use the 'AppendIfNoSuchLine' command and that'll work fine the
>first time around.  My issue is, what happens the next time I want to
>change that line?
>
>I could switch to the 'ReplaceLineWith' command, but that won't add the
>line if it doesn't exist.
>
>Is there a sensible way around this?  I'm guessing I might be missing
>something but a couple of dives through the refernce manual turned up
>naught.

The problem boils down to the difference between a configuration file
and ordinary text files.

There is currently no way in cfengine to say "this file /etc/system is a
configuration file, it has key/value pairs, and to set one you use the
template 'set x=y'".  I say currently because it's been my plan for the
last year to add this functionality.

But it's not all lost... I currently have a template of editfiles
commands to do almost the same thing:

Given a file X, a variable Y, and a value Z, I do something like this:

control:

  X_Y = ( Z )

editfiles:

  { X
      BeginGroupIfNoLineMatching '^Y =.*'
          Append 'Y ='
      EndGroup
      ResetSearch 1
      LocateLineMatching '^Y =.*'
      ReplaceLineWith 'Y = $(X_X)'
  }

which roughly translates into 'if there's no Y in the config file, edit
it.  now there's a Y, so find it, and replace it with the correct
line'.

So you want something like:

 { /etc/system
     BeginGroupIfNoLineMatching '^set shmsys:shminfo_shmmax=.*'
         Append 'set shmsys:shminfo_shmmax='
     EndGroup
     ResetSearch 1
     LocateLineMatching '^set shmsys:shminfo_shmmax=.*'
     ReplaceLineWith 'set shmsys:shminfo_shmmax=4294967296'
 }

I also wrote an article on it for work:

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

To make things easier (and remove the chance for error) I've got some M4
macros that autogenerate these templates.  At the above url I plan to
write more about our cfengine installation over the next few weeks.

-- 
[EMAIL PROTECTED]                           http://spacepants.org/jaq.gpg
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to