I am getting errors that the promised line insertion could not select an edit region in the file.

The only difference between manage_variable_values_ini and set_variable_values_ini is that manage_variable_values_ini contains a delete_lines promise to remove everything inside of the section before inserting. I am probably missing something obvious here, need more eyes.


Running 3.3.5
Here is the gist including standalone policy run output and testfile after run
https://gist.github.com/3444820

Also attached here

 !! The promised line deletion (.*) could not select an edit region in 
/tmp/testfile.txt (but the delimiters were expected in the file)
 !! The promised column edit (#+variable1\s*=.*) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 71
 !! The promised column edit (#+variable2\s*=.*) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 71
 !! The promised column edit (#+variable3\s*=.*) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 71
 !! The promised column edit (variable1\s*=.*) could not select an edit region 
in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 77
 !! The promised column edit (variable2\s*=.*) could not select an edit region 
in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 77
 !! The promised column edit (variable3\s*=.*) could not select an edit region 
in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 77
 !! The promised line insertion (variable1=var1) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 92
 !! The promised line insertion (variable2=var2) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 92
 !! The promised line insertion (variable3=var3) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 92
 !! The promised line deletion (.*) could not select an edit region in 
/tmp/testfile.txt (but the delimiters were expected in the file)
 !! The promised column edit (#+variable1\s*=.*) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 71
 !! The promised column edit (#+variable2\s*=.*) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 71
 !! The promised column edit (#+variable3\s*=.*) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 71
 !! The promised column edit (variable1\s*=.*) could not select an edit region 
in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 77
 !! The promised column edit (variable2\s*=.*) could not select an edit region 
in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 77
 !! The promised column edit (variable3\s*=.*) could not select an edit region 
in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 77
 !! The promised line insertion (variable1=var1) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 92
 !! The promised line insertion (variable2=var2) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 92
 !! The promised line insertion (variable3=var3) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 92
 !! The promised line deletion (.*) could not select an edit region in 
/tmp/testfile.txt (but the delimiters were expected in the file)
 !! The promised column edit (#+variable1\s*=.*) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 71
 !! The promised column edit (#+variable2\s*=.*) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 71
 !! The promised column edit (#+variable3\s*=.*) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 71
 !! The promised column edit (variable1\s*=.*) could not select an edit region 
in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 77
 !! The promised column edit (variable2\s*=.*) could not select an edit region 
in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 77
 !! The promised column edit (variable3\s*=.*) could not select an edit region 
in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 77
 !! The promised line insertion (variable1=var1) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 92
 !! The promised line insertion (variable2=var2) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 92
 !! The promised line insertion (variable3=var3) could not select an edit 
region in /tmp/testfile.txt
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './test_manage_variable_values_ini.cf' 
near line 92
[section1]
body common control {

bundlesequence => {
"main",
};

}

bundle agent main 
{
vars:
  "array[section1][variable1]" string => "var1";
  "array[section1][variable2]" string => "var2";
  "array[section1][variable3]" string => "var3";

files:
  "/tmp/testfile.txt"
    create => "true",
    edit_line => manage_variable_values_ini("main.array", "section1");
  

}

# These pulled from current copbl repository

bundle edit_line manage_variable_values_ini(tab, sectionName) {
 # Sets the RHS of configuration items in the file of the form
 # LHS=RHS
 # If the line is commented out with #, it gets uncommented first.
 # Adds a new line if none exists.
 # Removes any variable value pairs not defined for the ini section
 # The argument is an associative array containing tab[SectionName][LHS]="RHS"
 # don't change value when the RHS is dontchange

 # Based on set_variable_values_ini 
 # Added delete lines section to empty out undefined variable values for INI 
section

 # CAUTION : for it to work nicely, you should use Cfengine with the commit 
n°3229
 # otherwise you may risk a segfault

 #
 # If you are running 3.2.1 or earlier or more specifically git commit # or
 # earlier you can use this to work around the segfault bug.
 # vars:
 #     "$(file)"
 #         edit_line => append_if_no_line("[#EOF#]"),
 #         create => "true",
 #         comment => "Work around bug<bug#here> where eof did not mean end
 #                     of section and thus cannot select a region. This promise
 #                     should be placed before your call to this bundle";
 #      "$(file)"
 #         edit_line   => manage_variable_values_ini("context.array", 
"SectionName"),
 #         create => "true",
 #         comment     => "Set the variale values only in the specified ini 
region";
 # 

    vars:
        "index" slist => getindices("$(tab)[$(sectionName)]");

    # Be careful if the index string contains funny chars
        "cindex[$(index)]" string => canonify("$(index)");

    classes:
        "edit_$(cindex[$(index)])"     not => 
strcmp("$($(tab)[$(sectionName)][$(index)])","dontchange"),
                                   comment => "Create conditions to make 
changes"; 

    field_edits:

    # If the line is there, but commented out, first uncomment it
        "#+$(index)\s*=.*"
            select_region => INI_section("$(sectionName)"),
            edit_field => col("=","1","$(index)","set"),
            ifvarclass => "edit_$(cindex[$(index)])";

    # match a line starting like the key something
        "$(index)\s*=.*"
            edit_field => 
col("=","2","$($(tab)[$(sectionName)][$(index)])","set"),
            select_region => INI_section("$(sectionName)"),
            classes => 
if_ok("manage_variable_values_ini_not_$(cindex[$(index)])"),
            ifvarclass => "edit_$(cindex[$(index)])";

    delete_lines:
        ".*"
            select_region => INI_section("$(sectionName)"),
            comment       => "Remove all entries in the region so there are no 
extra entries";

    insert_lines:
        "[$(sectionName)]"
                location => start,
                 comment => "Insert lines";

        "$(index)=$($(tab)[$(sectionName)][$(index)])",
                select_region => INI_section("$(sectionName)"),
                ifvarclass => 
"!manage_variable_values_ini_not_$(cindex[$(index)]).edit_$(cindex[$(index)])";

}
body select_region INI_section(x)
{
select_start => "\[$(x)\]\s*";
select_end => "\[.*\]\s*";
}   
body edit_field col(split,col,newval,method)
{
field_separator    => "$(split)";
select_field       => "$(col)";
value_separator    => ",";
field_value        => "$(newval)";
field_operation    => "$(method)";
extend_fields      => "true";
allow_blank_fields => "true";
}
body classes if_ok(x)
{
promise_repaired => { "$(x)" };
promise_kept => { "$(x)" };
}
body location start
{
before_after => "before";
}     
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to