Forum: Cfengine Help
Subject: Looking for suggestions on ordering
Author: Authority
Link to topic: https://cfengine.com/forum/read.php?3,17628,17628#msg-17628

Normal ordering for edit_line bundles puts insert_lines before 
replace_patterns.  For my current problem, I'm trying to reverse them.

Given a simple syntax like this:

option = value

I would like to check that the option exists and simply replace the current 
value with the new value and if the option doesn't exist, add the line.  This 
is problematic though because the syntax of my files are flexible regarding 
white space but insert_lines is not.  If my insert_lines promiser does not have 
any whitespace around the equals sign but the file does, or if the option is 
indented, even though the option and value are as they should be, Cfengine will 
insert a new line.  Replace_patterns is powerful enough to handle and preserve 
whitespace but I'm having trouble stopping the insert_line from happening after 
replace_patterns has already done its work.  I only want the insert_line to 
happen if the replace_pattern couldn't find and replace the value.

I've found that a replace_patterns promise that doesn't match anything (and 
thus doesn't replace anything) is still marked as kept, which I can kind of 
understand (nothing to do is just as good as already being done), but it makes 
it very hard to determine if replace_patterns took any action.

I've tried setting a class at the start of the bundle that blocked the 
insert_lines promises and was cancelled by replace_patterns, but that class was 
reactivated when the bundle was re-evaluated so my inserts never happened.

I'm not going to argue that the normal ordering be changed as I think for most 
cases, it is optimal already, but I'm wondering if a new promise result class 
attribute (for use in class bodies) might be worthwhile, something along the 
lines of match_found, that would activate classes if the regex in the current 
promise succeeded.

Has anyone else dealt with such ordering issues?  Any suggestions/tricks on how 
to do this?

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

Reply via email to