Forum: Cfengine Help
Subject: Commands Promise: module => true.  External created variables not 
useable within other functions
Author: joe77
Link to topic: https://cfengine.com/forum/read.php?3,22378,22378#msg-22378

Hi,
i have a problem concerning the "transfer" of a variable to a function which 
was read via the commands promise "module" -> true.
It starts the script "zonesscript" which contains:   
/bin/echo =regex= VM.*

This creates a new variable (zonesscript.regex) within cfengine.
I can use the value (=VM.*) within parts of Cfengine without any problems. I 
can make a report promise and the correct value is used.
But if want to use the value of the variable in the bundle edit_line fillzones 
() it is simply not working. (see example below)
The value of the variable zonescript.regex  is NOT transfered to the getfields 
Function. Although i can make a report promise and "print" $(r) with the 
correct value. The getfieldsfunction is NOT using them at all. If i replace:

"zones_nr" int => getfields("$(r)","$(g.zones_csvdata)",";","zones_array");

with:

"zones_nr" int => getfields("VM.*,"$(g.zones_csvdata)",";","zones_array");
everything works. But i want the input from the script....

How can i use the value of the variable "regex" from the external "zonesscript" 
within getfields() function?

Thanks (again) for your help.
----------------------------------------------

Simplified Example. May contain (other) errors cause i cut out several lines to 
make it shorter:
------------------------
body common control{

bundlesequence => {"cfg_init_zones", "cfg_create_zones"};
}
bundle common g {
vars:
# Several unimportant vars (not included in this example)

bundle agent cfg_init_zones {
commands:
zones::
"$(g.zones_script)"
module => "true"; }

bundle agent cfg_create_zones {
files:
   "$(g.zones_template_output)"
        create =>"true",
         edit_line => fillzones("$(g.zones_temp_file)", "$(zonesscript.regex)");
}
bundle edit_line fillzones(template,r)
{
 vars: 
        "zones_nr" int => 
getfields("$(r)","$(g.zones_csvdata)",";","zones_array");
        "zones_idx" slist    => getindices("zones_array");
 
 insert_lines:
 # no complete example
 }

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to