Forum: CFEngine Help
Subject: Re: RE: CFEngine Help: Re: CFEngine Help: weird error on variable and 
report not working
Author: zzamboni
Link to topic: https://cfengine.com/forum/read.php?3,23210,23492#msg-23492

Hi Jerome,

Just to complete the thought: one problem with using a plain insert_lines is 
that it would not handle properly the case in which the "vi" alias is already 
defined, but with some other value. In this case you want to replace the 
existing line with the correct definition, or insert it if there is no such 
line already.

For cases like this, I wrote a replace_or_add bundle that you can find here: 
https://github.com/zzamboni/cfengine-copbl/blob/master/cfengine_stdlib.cf#L348

And you would use it like this:

  files:
     "$(g.bashrc_loc)"
        edit_line => replace_or_add("alias\s+vi\s*=.*", "$(g.alias_vi)"),
        classes => if_repaired("alias_inserted");


This has the effect of replacing any previous definition of "alias vi" (as 
indicated by the regular expression in the first parameter) with the correct 
value as given in the second parameter.

Best regards,

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

Reply via email to