Forum: Cfengine Help
Subject: Re: Strange behaviour with insert_lines
Author: zzamboni
Link to topic: https://cfengine.com/forum/read.php?3,18780,18795#msg-18795

I have written an edit_line body called replace_or_add, which I think could be 
useful for what you want to achieve. It takes a regular expression and a line - 
if the regex matches, then the matching line is replaced with the given line, 
and if nothing matches, then the line is added. I use it to make small changes 
in files, for example:

  "/etc/ssh/sshd_config"
  handle => "sshdconfig_only_protocol2",
  comment => "Ensure only ssh protocol v2 is enabled",
  edit_line => replace_or_add("^# *Protocol 2,1.*$","Protocol 2"),
  classes => if_repaired("restart_sshd");

This is used to modify the stock sshd_config to allow only Protocol 2.

(Although, for this particular case, my set_config_values body is perhaps a 
better way of achieving it, it uses both edit_field and insert_line as needed).

You can find my version of cfengine_stdlib here: 
http://github.com/zzamboni/cfengine-copbl (I should probably submit these 
changes to cfengine at some point).

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

Reply via email to