Forum: Cfengine Help
Subject: Re: Promise to maintain sections of a file
Author: toddnni
Link to topic: https://cfengine.com/forum/read.php?3,22435,22461#msg-22461

Hi,

My bundle which is something like

bundle edit_line lines_between_delimiters(com,tag,lines) {

vars:
  any::
    "start_limiter_reg"
      string => "$(com)\[$(tag)-begin\]";
    "end_limiter_reg"
      string => "$(com)\[$(tag)-end\]";

delete_lines:
  any::
    ".*"
      comment => "Delete all lines between the delimiters. This way we can
      modify the lines.",
      select_region => in_between("$(start_limiter_reg)","$(end_limiter_reg)");

insert_lines:
  any::
    "$(lines)"
      comment => "Text between the delimiters.",
      select_region => in_between("$(start_limiter_reg)",
        "$(end_limiter_reg)");
}

body select_region in_between(start,end) {

  select_start => "$(start)";
  select_end => "$(end)";
}

seems to work perfectly. Cfengine updates the text between delimiters nicely. 
In the example I have assumed that the delimiters exist. I must admit that I 
had some problems with this in previous cfengine versions, but now (version 
3.1.5) a bundle like this works.

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

Reply via email to