Forum: CFEngine Help
Subject: Re: How to add to line with field_edits?
Author: bbomgardner
Link to topic: https://cfengine.com/forum/read.php?3,22981,22990#msg-22990

You need to let cfengine know that uri is the field and the rest are subfields. 
Its confusing because a space is the deliminator between those two and between 
each of the subfields.

This won't be exactly what you want (the regex is generic so the file must 
contain 'uri ' already), but see if this makes sense:


body common control {
bundlesequence => { "test" };
}

bundle agent test {
vars:

  "serverlist" slist => { "server1", "server2", "server3" };

files:

  "/tmp/blah"
    handle => "test_file",
    comment => "This is my favorite file.",
    create => "true",
    edit_line => modify_value_parameters("uri"," ","2"," 
","$(serverlist)","alphanum");
}


bundle edit_line modify_value_parameters(o,delim,field,vsep,v,act) {

# Use this bundle to make precision edits to a list of parameters in a value 
set for a specific option.
# Parameters
#  option,field deliminator,field to edit (starts at 1),subfield 
deliminator,subfield value,action (prepend, append, delete, set, alphanum)
#
# Example
# edit_line => modify_value_parameters("VARIABLE","\"","1"," ","four","append");
#
# Applied to this line
#    VARIABLE="one two three"
# becomes
#    VARIABLE="one two three four"

vars:

  "val" slist => { @(v) };

field_edits:

  "\s*$(o)\s*$(delim).*",
    comment => "Modify list of parameters in value for a specific option in 
file.",
    edit_field => 
tabular_edit("$(delim)","$(field)","$(vsep)","$(val)","$(act)");
}

#########################################################
body edit_field tabular_edit(split,col,vsep,newval,method)
{
field_separator    => "$(split)";
select_field       => "$(col)";
value_separator    => "$(vsep)";
field_value        => "$(newval)";
field_operation    => "$(method)";
extend_fields      => "true";
allow_blank_fields => "true";
}


_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to