Forum: CFEngine Help
Subject: Re: CFEngine Help: Regular expression error "nothing to repeat"
Author: dpullman
Link to topic: https://cfengine.com/forum/read.php?3,26110,26128#msg-26128
No luck getting escape to work, but that may be because I'm not able to get it
work in this context? Basically I tried something like this:
"escape($(index))\s*.*"
But I don't think it evaluates the escape function such that it would escape
the special characters. I couldn't figure out a way to get a corresponding
list in the vars section that would be addressable in conjunction with the
original index list, i.e., like:
"eindex[$(index)]" string => escape("$(index)");
So basically I flipped set_config_values around so that the syslog.conf target
is the index and the selector is the value. That way the special characters
are not in the index, and I avoid the need to escape. In the example below I'm
also avoiding uncommenting existing lines so as to not have duplicates. In my
testing, and in some experience with syslog.conf maintainers, sometimes they
would comment out the old line and put a new line below it. Before I told it
to ignore commented lines, I would get two edited lines, one the old commented
line and the other the new edited line.
Here's the current working version:
bundle agent base_config {
vars:
any::
"syslog_conf[@cf3test.el.nist.gov]" string => "local4.info";
"syslog_conf[@loghost.mel.nist.gov]" string =>
"*.notice;auth.info;authpriv.*;remoteauto.crit;ftp,install,internal.none";
files:
"/etc/syslog.conf"
edit_line => set_syslog_values("base_config.syslog_conf"),
classes => if_repaired("restart_syslogd");
processes:
restart_syslogd::
"syslogd" signals => { "hup" };
}
# Based on set_config_values
bundle edit_line set_syslog_values(v)
{
vars:
"index" slist => getindices("$(v)");
"cindex[$(index)]" string => canonify("$(index)");
field_edits:
"[^#]+.*\s*($(index))"
edit_field => col("\s+","1","$($(v)[$(index)])","set"),
classes => if_ok("not_$(cindex[$(index)])");
insert_lines:
"$($(v)[$(index)]) $(index)",
ifvarclass => "!not_$(cindex[$(index)])";
}
Comments and suggestions welcome. We'll be testing this in the near future and
I'll update with any changes from testing or from the forum.
Thanks!
--David
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine