On Wed, Aug 18, 2010 at 11:37 AM, Mark Burgess wrote:
> Try this
> http://www.cfengine.org/manuals/cf3-solutions.html#Add-variable-definitions-to-a-file
Thanks, that was exactly what I needed!
For Google and list readers looking to configure /etc/ssh/sshd_config
with CFengine3:
I created a new bundle "set_keyword_values()" based on
set_variable_values() in cfengine_stdlib.cf - sshd_config uses
"keyword value" pairs without an equals-sign in between. I hope I
didn't mess up the regexps too much, just replaced the "=" with a
space ;-)
bundle agent sshd_config {
vars:
# Want to set these values by the names of their array keys
"rhs[Protocol]" string => "2";
"rhs[PermitRootLogin]" string => "without-password";
"rhs[UsePrivilegeSeparation]" string => "yes";
"rhs[PermitUserEnvironment]" string => "yes";
"rhs[X11Forwarding]" string => "yes";
files:
"/tmp/sshd_config"
create => "true",
edit_line => set_keyword_values("sshd_config.rhs");
}
#######################
# For your library.cf #
#######################
bundle edit_line set_keyword_values(v)
# Sets the RHS of keywords in the file of the form
# LHS RHS
# Adds a new line if non exists
{
vars:
"index" slist => getindices("$(v)");
# Be careful if the index string contains funny chars
"cindex[$(index)]" string => canonify("$(index)");
field_edits:
# match a line starting like "keyword value"
"$(index)\s* .*"
edit_field => col(" ","2","$($(v)[$(index)])","set"),
classes => if_ok("not_$(cindex[$(index)])");
insert_lines:
"$(index) $($(v)[$(index)])",
ifvarclass => "!not_$(cindex[$(index)])";
}
Mark, thanks for the quick response!
--
Met vriendelijke groet / Kind regards,
Ed Voncken.
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine