On 01/24/2012 05:20 PM, no-re...@cfengine.com wrote:
> Forum: CFEngine Help
> Subject: Re: CFEngine Help: Re: maintaining /etc/security/limits.conf with cf3
> Author: milindk
> Link to topic: https://cfengine.com/forum/read.php?3,24612,24641#msg-24641
> 
> Does this work ?

Thanks it works, but complains that its not properly convergent.

I changed the replace pattern to include a negative lookahead
"^(?!$($(v)[$(pattern)]))$(pattern)"

And it stopped complaining. So it does work, but boy

"limits[^\s*sybase\s*hard\s*memlock\s.*$]" string => "sybase hard
memlock 10000";

That seems like a poor way to communicate meaning.

Here is the edited version as well.

-- 
Nick Anderson <n...@cmdln.org>
body common control
{
bundlesequence => { "configfiles" };
inputs => { "/var/cfengine/masterfiles/cfengine_stdlib.cf" };
version => "1.2.3";
}

bundle agent configfiles
{
vars:
# Files to edit
"files[limits]" string => "/tmp/limits.conf";
"limits[^\s*sybase\s*hard\s*memlock\s.*$]" string => "sybase hard memlock 
10000";
"limits[^\s*sybase\s*soft\s*memlock\s.*$]" string => "sybase soft memlock 
unlimited";

methods:
"limits" usebundle => edit_limits;
}
bundle agent edit_limits
{
files:
"$(configfiles.files[limits])"
comment => "Make sure sysctl.conf contains desired configuration settings",
create => "true",
edit_line => replace_or_add("configfiles.limits"),
classes => if_repaired("limits_modified");

}

bundle edit_line replace_or_add(v)
{

vars:

"pattern" slist => getindices("$(v)");

"cpattern[$(pattern)]" string => canonify("$(pattern)");

classes:
"${cpattern[$(pattern)]}_parameter_found" expression => 
regline("$(pattern)","$(configfiles.files[limits])");

replace_patterns:
"^(?!$($(v)[$(pattern)]))$(pattern)"
replace_with => value("$($(v)[$(pattern)])"),
ifvarclass => "${cpattern[$(pattern)]}_parameter_found";


insert_lines:
"# End of file";
"$($(v)[$(pattern)])"
location => before("# End of file"),
ifvarclass => "!${cpattern[$(pattern)]}_parameter_found";

reports:
parameter_found::
"${pattern}";
}

body location before(str)
{
before_after => "before";
select_line_matching => "$(str)";
}
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to