Forum: CFEngine Help Subject: Re: delete_lines and select region Author: zzamboni Link to topic: https://cfengine.com/forum/read.php?3,26551,26559#msg-26559
Hi, Looking at the verbose output of running the policy, it seems this message is produced by the second and third passes CFEngine does over the delete_lines promise, *after* the region has been deleted. The message indicates that there was nothing to select (the region to delete is empty). As you had already realized, the message is harmless. One option to get rid of it would be to omit the -I option, which makes CFEngine less verbose in its output. Another option would be to modify the policy so that the delete_lines promise is only executed once, by using a class to flag when it has already been executed. Something like this: body common control { bundlesequence => { example }; inputs => { "/var/cfengine/inputs/cfengine_stdlib.cf" }; } bundle agent example { files: "/tmp/myfile" edit_line => editfile, create => "true"; } bundle edit_line editfile { vars: "sdelim" string => "#### CFENGINE ANCHOR"; # We do this to make the classname unique per filename, so that this bundle # can be used on different files without interference. "classname" string => concat(canonify("$(edit.filename)"),"_delete_region_done"); delete_lines: ".*" select_region => from_line("$(sdelim)"), classes => if_ok("$(classname)"), ifvarclass => "!$(classname)"; # I want to insert my anchor line if it is not present the first time insert_lines: "$(sdelim)"; } body select_region from_line(start) { select_start => "$(start)"; include_start_delimiter => "false"; } Now the delete_lines promise only gets evaluated when the given class is not defined, and that class gets defined after the promise is successfully evaluated, so that it will not be reevaluated in the second and third passes. Note that I included the canonized filename in the classname, so that the editfile bundle can be reused across the policy without interference. If you are sure this will not be the case, you can omit all the references to the $(edit.filename) variable and use a static class name. _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine