Forum: Cfengine Help Subject: Re: AppendIfNoLineMatching and Cfengine 3 Author: zzamboni Link to topic: https://cfengine.com/forum/read.php?3,19997,20002#msg-20002
Rob, I wrote some time ago an edit_line bundle called replace_or_add, which takes a regex and a line. If the regex matches any line, it is replaced by the given line. If no match is found, the line is appended. Maybe this will help with what you need? You can find it in my personal copy of cfengine_stdlib.cf at https://github.com/zzamboni/cfengine-copbl/blob/68cca90a922a8cb3efc519ec01cfad5bb354b389/cfengine_stdlib.cf#L350 Also here it is for reference: bundle edit_line replace_or_add(pattern,line) # Replace a pattern in a file with a single line. # If the pattern is not found, add the line to the file. # The pattern must match the whole line (it is automatically # anchored to the start and end of the line) to avoid # ambiguity. { replace_patterns: "^${pattern}$" replace_with => value("${line}"), classes => always("replace_done"); insert_lines: replace_done:: "${line}"; } body classes always(x) # Define a class no matter what the outcome of the promise is { promise_repaired => { "$(x)" }; promise_kept => { "$(x)" }; repair_failed => { "$(x)" }; repair_denied => { "$(x)" }; repair_timeout => { "$(x)" }; } _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine