Well first of all, look in cfengine_stdlib.cf - you might want to simply create 
a modified version of set_variable_values to do what you want (where you change 
the delimiter to "\s+" or something.

But more importantly, you have a fundamental misunderstanding of how edit_lines 
works.  Here's basically what happens in a single edit_line bundle:

1) Cfengine makes a copy of the file you are editing
2) Cfengine makes all the edits in the COPY of the file (it tries to do it all 
in memory, so no file I/O)
3) After all edits (delete_lines, field_edits, insert_lines, replace_patterns), 
Cfengine sees if the new file is the same as the old one
4a) If no differences, delete the copy
4b) If differences, i) copy your original file to file.cfengine_before_edits, 
ii) rename the edited version to your filename

In this way, there is no "window of opportunity".  The file looks one way, and 
then suddenly looks a different way.  You're safe!

The problem exists when you have TWO bundles editing the same file - then there 
really is a window of opportunity between the two sets of edits.  But if you 
use one edit_lines bundle, you're fine!

-Dan

On Oct 12, 2010, at 8:32 AM, no-re...@cfengine.com wrote:

> Forum: Cfengine Help
> Subject: Best practice in edit_lines
> Author: pieterb
> Link to topic: https://cfengine.com/forum/read.php?3,18695,18695#msg-18695
> 
> There a certain files where I want to make sure there is only one definition 
> of a certain attribute. For example, in /etc/nsswitch.conf, I want only one 
> instance of the line: "passwd     ldap files". 
> 
> The way I currently do this is search the whole file, delete all entries that 
> start with passwd, and then add the right one again. This is to make sure 
> only that specific entry is in my nsswitch file. 
> 
> I feel however that this is a pretty dirty way to do this; there is a small 
> window in which there is nothing defined in the file (e.g., step one deleted 
> all lines starting with .., but not added the correct one yet) that makes me 
> a bit uncomfortable.
> 
> How do you guys go about this?
> 
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to