Forum: CFEngine Help Subject: Re: Evaluation of bundlesequence with constructed mybundle(@(args)) Author: jblaine Link to topic: https://cfengine.com/forum/read.php?3,23499,23556#msg-23556
Seva Gluschenko Wrote: ------------------------------------------------------- > You must import slists locally in order to use > them in a bundle, e.g.: > > > bundle agent main > { > vars: > "servers" slist => { @(g.servers) }; > ... > } Seva, thanks for the reply. According to the CFEngine Reference, section 2.7.2 "List variable substitution and expansion", that should not be necessary as the variable is global in scope (... @(g.ntpservers) from "bundle common g"). Lists can be passed around in their entirety in any context where a list is expected During list expansion (jblaine: which I am not doing here), only local lists can be expanded, thus global list references have to be mapped into a local context if you want to use them for iteration (jblaine: which I am not doing here). I tried it anyway. That didn't buy me anything (got worse actually): /usr/local/sbin/cf-agent -D site_x -IK !! List parameter "ntpservers" not found while constructing scope "system_ntpclient_configure" - use @(scope.variable) in calling reference !! List parameter "servers" not found while constructing scope "ntpclient_config_edit" - use @(scope.variable) in calling reference I reverted. I did figure it out though. For some reason, which I would love to have explained by someone who knows why, I had to explicitly scope all of the variables involved all the way to the final actual expansion in the edit_line bundle. body common control { bundlesequence => { "main" }; # this works fine inputs => { @(g.inputfiles) }; } bundle common g { vars: any:: "commoninputs" slist => { "cfengine_stdlib.cf", "all.cf" }; "inputfiles" slist => { @(commoninputs), }, policy => "free"; site_x:: "ntpservers" slist => { "time.sitex.our.org", "time.sitey.our.org", }; "inputfiles" slist => { @(commoninputs), "site_x.cf", }, policy => "free"; } bundle agent main { methods: site_x: "site_x" usebundle => system_ntpclient_configure(@(g.ntpservers)); } bundle agent system_ntpclient_configure(servers) { files: any:: # Using @(g.ntpservers) here would mean this bundle could not be reused # unless implementers set some global var, which is lame. "/etc/ntp.conf" edit_line => ntpclient_config_edit(@(system_ntpclient_configure.servers)); } bundle edit_line ntpclient_config_edit(servers) { delete_lines: ".*"; insert_lines: "############################################################# ### This file is configured by CFEngine. ### Manually editing the file might lead CFEngine ### to change back its content ############################################################# server 127.127.1.0 fudge 127.127.1.0 stratum 10" insert_type => "preserve_block", location => start; # Using $(g.ntpservers) here would mean this bundle could not be reused # unless implementers set some global var, which is lame. "server $(servers)"; } _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine