Forum: Cfengine Help Subject: Promise to maintain sections of a file Author: jtl Link to topic: https://cfengine.com/forum/read.php?3,22435,22435#msg-22435
Hi help-cfengine, I am trying to get cfengine to automatically insert and maintain multi-line sections of a text file. Is this possible to do with an edit_line bundle? When the appropriate class is defined, cfengine should insert appropriate section delimiters. Within that section, maintain the multi-line string, and delete anything that doesn't match the multi-line string. I've tried a number of different methods but as yet have not found one that works or converges properly. One actually resulted in a crash ( https://cfengine.com/bugtracker/view.php?id=653 ) which Mark promptly fixed and changed the code to print a warning that what I was attempting ( multiline delete_lines where not_matching is true ) is not supported. :-) Here's the prototype: bundle edit_line uvm_insert_block_comment_section(commentmark, sectionname, insertstring) { # Commentmark is typically "#", sectionname is "foo", insertstring is typically multi-line insert_lines: # Insert the section header/footer "$(commentmark) BEGIN CFENGINE-INSERTED SECTION $(sectionname)"; "$(commentmark) END CFENGINE-INSERTED SECTION $(sectionname)"; # Insert the content "$(insertstring)" select_region => uvm_select_block_comment_section($(commentmark), $(sectionname)); } body select_region uvm_select_block_comment_section(commentmark, sectionname) { select_start => "$(commentmark) BEGIN CFENGINE-INSERTED SECTION $(sectionname)"; select_end => "$(commentmark) END CFENGINE-INSERTED SECTION $(sectionname)"; } This does the proper insertion after a couple of cf-agent runs (one to insert the section headers, then one to insert the section contents) but does not effectively maintain the section if a user modifies the section. I've tried delete_lines: ".*" within the section but this does not converge (because it still matches the replaced string.) replace_patterns has a similar problem. I've tried delete_lines "$(insertstring)" not_matching => true but that is not supported (see above bug report). Using a separate template file and expand_template would be one way to do this, but I am trying to avoid having to tell other admins that in order to edit a non-maintained section of a config file they must run cf-agent manually in order to test. Anyone doing anything like this? Best, Jim Lawson University of Vermont _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine