help-cfengine
[Top][All Lists]
Advanced

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

editfiles question


From: Sven Mueller
Subject: editfiles question
Date: Tue, 31 Aug 2004 13:22:55 +0200
User-agent: Thunderbird 0.7.3 (Windows/20040803)

Hi.

From the documentation, I am not certain how to achieve the following task. Let's say I want to edit /etc/passwd (actually I am editing a similarly formated, but different file), and I want the following to be achieved:

- I want the file to be created if it doesn't exist (AutoCreate takes
  care of this)
- I want a line "root:..1234567890123:0:0::/bin/bash" be added to the
  file if it doesn't exist, overwriting any root:.* lines that might
  exist.

I guess that I need to use ReplaceLinesMatchingField "1" somewhere, but how exactly do I use it?

I know the example in http://www.cfengine.org/confdir/fieldmatch.html, but I don't want to use a temporary file (for several reasons) and it seems to me that the example there _always_ edits the file, which I specifically want to avoid (because I want to define a class only if the file was actually changed).

If it isn't possible to avoid that editing on every run of cfagent, I would suggest introducing some sort of "ReplaceAppendMatchingField" function to allow just that: Replace existing lines matching the given Field, appending the current line if no match was found, to be used like this:

SetLine "root:..1234567890123:0:0::/bin/bash"
ReplaceAppendMatchingField 1

That would (in my opinion at least) be far more readable and easier to maintain than what my guess would currently be:

{ /etc/passwd
AppendIfNoLineMatching "root:.*" "root:..1234567890123:0:0::/bin/bash"
SetLine "root:..1234567890123:0:0::/bin/bash"
ReplaceLinesMatchingField 1
AutoCreate
DefineClasses "passwd_edited"
}

Though the question remains: Would the above lines work correctly? And
would "passwd_edited" _only_ be defined if the file was actually changed? I'm not really certain how I should test this, otherwise I wouldn't ask.

cu,
sven




reply via email to

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