Dan,
the useful policy to keep in mind all the time while creating either
cfengine promises or any other piece of code is KISS (keep it safe and
simple).
I've proposed a generic edit_line bundle for /etc/fstab adjustment
recently which can be easily adapted to handle almost any space
separated file:
bundle edit_line config_option_space_separated(name,value)
{
classes:
"not_there" not => regline("$(name)\s+$(value)(\s+.*)$",
"$(edit.filename)");
not_there::
"wrong_value" expression => regline("$(name)\s+.*",
"$(edit.filename)");
delete_lines:
wrong_value::
"$(name)\s+" comment => "remove any incorrect values";
insert_lines:
not_there::
"$(name) $(value)";
}
Now you can call it like
files:
"/tmp/main.cf"
edit_line =>
config_option_space_separated("smtp_host", "smtp.example.net");
2010/12/9 Daniel Dehennin <[email protected]>:
> Daniel Dehennin <[email protected]> writes:
>
> [...]
>
>> The replace_patterns is always repaired:
>
> [...]
>
> Even a simple one like this:
>
> #v+
> cat /tmp/main.cf:
> smtp_host smtp.example.net2
> #v-
>
> #v+
> replace_patterns:
>
> HasSMTPhost::
> "^(smtp_host)\s+smtp\.example\.net$" replace_with =>
> value("$(match.1) $(smtp)2"),
> classes => if_repaired("SomeSMTPHostReplaced"),
> comment => "Replace missconfigured smtp_host";
> #v-
>
> with:
>
> #v+
> body classes if_repaired(x)
> {
> promise_repaired => { "$(x)" };
> }
> #v-
>
>
> #v+
> /usr/sbin/cf-agent -K
> R: I replace some missconfigured smtp_host line
> #v-
>
> I'll look at the code when I'll have time.
>
> Thanks.
> --
> Daniel Dehennin
> Récupérer ma clef GPG:
> gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1
>
> _______________________________________________
> Help-cfengine mailing list
> [email protected]
> https://cfengine.org/mailman/listinfo/help-cfengine
>
>
--
SY, Seva Gluschenko.
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine