Talk:Editfiles Examples

From Cfwiki

Jump to: navigation, search

While 'EmptyEntireFilePlease' doesn't sound like a convergent process, the file isn't actually rewritten if it doesn't differ from what would be created by the Append statements. (I use AppendIfNoSuchLine, because Append generates errors about non-convergence outside of a Group (as in the first example)).

It may save some compute time to first look for a header or version, but for some jobs, it may not be worth the extra complexity.

(Hope this is appropriate place for this comment, haven't used the wiki much yet...)

-Ebrown (Note to Ebrown: please don't sign your postings with '-Ed', that's what User:joshr's been doing up to now.]

The problem with AppendIfNoSuchLine is you can't insert repetitive lines that occur in many files, ie: blank lines, common lines in printcap or ini style files, etc.

Append is specifically used so that the entire file can be encapsulated into an editfiles stanza.

I had noticed that EmptyEntireFilePlease behaved that way, but felt it was wasteful or just incorrect to rely on it not overwriting an existing file.

-- RussellAdams 2004-Dec-16

The first example doesn't work as outlined by Ebrown. You cannot use "Append" outside a group, as it gives this error: "Append used outside of Group - non-convergent". What you instead need to do is something like this:

editfiles:

   any::
       { /etc/hosts
           BeginGroupIfFileExists "/etc/hosts"
               EmptyEntireFilePlease
               Append "127.0.0.1       localhost"
               Append "192.168.1.254   myrouter"
           EndGroup
       }

Furthermore, adding "AutoCreate" before the BeginGroup... may be a good idea as well.

--peterhoeg 2005-May-09

Contents

Variables across multiple files

While integrating the RCS variables into some of my other configurations, I've had issues with the redefinition of the RCSRev, RCSSource, and EditHeaders variables not occurring. This means that there are conflicts between multiple editfiles stanzas in other files that may affect editing.

If I come up with a workaround, I'll post it immediately.

Until such time, using hand coded or "static" version numbers with full file replacement is still very reliable.

--RussellAdams 24-Dec-2004

Variables across multiple files revisited.

It appears that unique variable names must be used for each RCS variable for the edit file headers.

I had hoped to reuse the variable names, but there were persistant problems between multiple files in my import hierarchy.

As a result, I renamed all the RCS variables with a prefix which specifies the filename.

With that in place, it works fine.

--RussellAdams 24-Dec-2004

Non-convergent?

I've not been at this long but selecting targets for this process you describe would appear to require great care. I think, for example, that /etc/system on a Solaris system would be a poor target as installers such as Oracle can make entries that cannot be removed without breaking things.

dp

Careful selection of editfiles

I agree you must be careful in applying any changes with editfiles.

Normally, adding or removing a single line to a file is ok.

The method I discussed of emptying the file and replacing the entire contents when there is an update is not suitable for any files updated from any other source than cfengine.

I do however, combine the empty file / recreate method with Managing Blocks of Code with Editfiles to allow me to have a base configuration and then add on changes from other cfengine files.

For instance, I manage my ssh known_hosts files with empty file / recreate for all systems, and then specific boxes that need additional host signatures I add with the techique from Managing Blocks of Code with Editfiles.

That way, when the file is recreated, any changes are reapplied in short order, depending on ifelapsed.

Russell

Exactly what I'm looking for

Your article on managing blocks of code is great. I very much want to manage certain things at the file level: sudoers, resolv.conf, bind tables, etc., but others need a bit more fine tuning. Host tables, for example, sendmail.mc files, apache conf files, jumpstart files, etc. This is some good reading. I'll go see what I can break, now.

dp

Personal tools