Forum: Cfengine Help
Subject: Re: Insert line when regexp does not match
Author: Seva Gluschenko
Link to topic: https://cfengine.com/forum/read.php?3,18868,18869#msg-18869

There was a very nice cf2 to cf3 syntax conversion tool on cfengine.com site. 
Can't find it now, though. Perhaps, Mark decided it isn't needed anymore?

Anyway, your task can be solved like this:

bundle agent foo
{
 files:
    "/tmp/foo"
          edit_line => add_if_absent("x*yz", "new line"),
          classes   => if_repaired("action");
}

bundle edit_line add_if_absent(pattern,addition)
{
 classes:
    "not_there" not => regcmp("$(pattern)", "$(edit.filename)");

 insert_lines:
    not_there::
          "$(addition)"
                    comment => "only add the line when no $(pattern) is 
present";
}

body classes if_repaired(x)
{
 promise_repaired => "$(x)"';
}


Also I'd suggest to use less generic (more specific) class name since classes 
defined by the compound body (classes) become global.

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

Reply via email to