Hi,
I've been working on putting together an edit_line bundle that does
the following:
- If a certain pattern exists, replace it with a given string
- If the pattern does not exist, add the line to the file.
Below is what I came up with, which works, but somehow feels inelegant
because I have to pass it the filename for the check using regline. I
tried doing it by setting different classes in the replace_patterns:
and insert_lines: sections, but could not get it to work.
I would appreciate any ideas! I am just learning cfengine, so this is
as much an intellectual exercise as something I need (and maybe could
be a useful addition to the stdlib?)
Thanks,
--Diego
bundle edit_line replace_or_add(file,pattern,line)
{
classes:
"lineexists" expression => regline("$(pattern)","$(file)");
replace_patterns:
lineexists::
"${pattern}"
replace_with => value("${line}");
insert_lines:
!lineexists::
"${line}";
}
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine