Forum: CFEngine Help
Subject: Re: delete_lines and select region
Author: jbdenis
Link to topic: https://cfengine.com/forum/read.php?3,26551,26634#msg-26634

A big thank you to both of you for rephrasing more clearly to me what is 
already in the documentation.

I think I've been misguided by some of my test. 

Imagine the initial file contains only the anchor line :


# cat /tmp/myfile
#### CFENGINE ANCHOR
#


If I run this test :


# cat test.cf 
body common control
{
        bundlesequence  => { example };   
        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 => canonify("$(edit.filename)");

  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:
      "1";
      "2";
      "3"; 
}

body select_region from_line(start)
{
        select_start => "$(start)";
        include_start_delimiter => "false";
}  


The insert_lines statement are not honored :


# cat /tmp/myfile
#### CFENGINE ANCHOR


The verbose output is of the run is here : https://gist.github.com/3171142

But if I add an empty line at the end of this file (to give something to delete 
to delete_lines), everything is fine :

# echo >> /tmp/myfile
# cf-agent -K -f ./test.cf
# cat /tmp/myfile
#### CFENGINE ANCHOR
1
2
3


>From the verbose output, we can see that the class "guard" classname is not 
>defined because there is nothing to delete, hence the result. I guess I'll 
>have to tweak my promise or find another way. 

I've got another test I wanted to post, but your answers confirmed that there 
is definitively something wrong on my side. 

Thank you again for the help.

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

Reply via email to