On 04/30/2012 10:46 PM, Nick Anderson wrote:
I am just now starting to write some policy that uses the new template feature, its nice but I did notice that it seems I need to reference all variables globally.Is it intended behavior that the variable expansion for edit_template requires variables to be referenced globally? I can see that all of the variables in the documentation examples are referenced globally but I did not see any notes that mentioned it is specifically required.
Nick what do you mean that you have to put the parameters in common bundle?This is my setup. In all the template files i use. I don't have to remember in which bundle the variables are set and all parameters are slist variables.
* $(template.cfg[<variabele>] I have to setup some default ones: template.cf: bundle agent template(params) { vars: any:: # An array of configuration parameters used in template files # "cfg[cacert_file]" slist => { "/etc/ssl/certs/ca-certificates.crt" }, policy => "overridable"; "cfg[domain_name]" slist => { "sara.nl" }, policy => "overridable"; "cfg[domain_search]" slist => { "sara.nl" }, policy => "overridable"; "cfg[domain_server]" slist => { "145.100.5.47", "145.100.5.30" }, policy => "overridable"; ## Copy configuration parameters passed, into a local array # "param_keys" slist => getindices("$(params)"); ## List overriding # "cfg[$(param_keys)]" slist => { "@($(params)[$(param_keys)])" }, policy => "overridable"; "domain_search_string" string => join(" ", "template.cfg[domain_search]"), policy => "overridable"; } Now each machine/cluster can sets its own parameters: cluster.cf ## Set resolv.conf parameters # "varray[domain_name]" slist => { "irc.sara.nl" }, policy => "overridable"; "varray[domain_search]" slist => { "irc.sara.nl", "sara.nl" }, policy => "overridable"; ## Initialize template_variables # "templates" usebundle => template("cluster.varray"); example template: {{{ [%CFEngine BEGIN %] search $(template.domain_search_string) [%CFEngine END %] [%CFEngine BEGIN %] nameserver $(template.cfg[domain_server]) [%CFEngine END %] }}} -- ******************************************************************** * Bas van der Vlies e-mail: b...@sara.nl * * SARA - Academic Computing Services Amsterdam, The Netherlands * ********************************************************************
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine