Forum: CFEngine Help
Subject: Re: Implicit looping in an slist array
Author: milindk
Link to topic: https://cfengine.com/forum/read.php?3,25939,25943#msg-25943

You can process slist array similar to string array 
but inside agent bundle you need to assign it to local slist variable before 
you can exapnd it  , as expansion of global slist is not allowed 

Here is a something that I am using , hope it helps 

body common control
{
bundlesequence => { globalvars, 
loblocalvars("globalvars.ibdefvars","globalvars.ibdefslvars"), main };
 inputs => { "/var/cfengine/masterfiles/cfengine_stdlib.cf" };
version => "1.2.3";
}
#bundle common globalvars
bundle agent globalvars
{
vars:

"ibdefvars" string => "abra-ka-debra",
      policy => "overridable";

"ibdefvars" string => "rotate",
      policy => "overridable";

"ibdefvars" string => "5",
      policy => "overridable";


"ibdefslvars" slist => { "string" ,"ping" },
      policy => "overridable";

"ibdefslvars" slist => { "john", "doe" },
      policy => "overridable";
classes:

}


bundle agent loblocalvars(defvars,slvars)

{

vars:
"param_keys" slist=> getindices("$(defvars)");

"ibvars[$(param_keys)]"  string => "${${defvars}[$(param_keys)]}",
 policy => "overridable";

"parm_keys" slist=> getindices("$(slvars)");

"ibslvars[$(parm_keys)]"  slist => { "@{${slvars}[$(parm_keys)]}" },
 policy => "overridable";


classes:

reports:
}

bundle agent main

{

methods:
  "any" usebundle => 
array_slists("loblocalvars.ibvars","loblocalvars.ibvars","loblocalvars.ibslvars");
  "any" usebundle => slists("loblocalvars.ibslvars");

}

bundle agent array_slists(s,n,v)
{
vars:
 "v1" slist => { "@{${v}}" };
classes:

reports:
cfengine_3::
"string ${${s}} ";
"string  ${${n}}";
"slist ${v1}";
}

bundle agent slists(s)
{
vars:
 "sl" slist => { "@{${s}}" };
classes:

reports:
cfengine_3::
"slist ${sl}";
}

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

Reply via email to