Is it expected behavior that you cannot create new index values with a list?
If I do a simple array creation with a list it seems to work
https://gist.github.com/3684884 (set_array_values_with_list.cf)
cf-agent -KIf ./set_array_values_with_list.cf
R: Array: local_array[id1]=value
R: Array: local_array[id2]=value
R: Array: local_array[id3]=value
But if I am overriding array variables, It does not appear that I can
create new ones. See how local_array[blue] is not set or reported, but
local_array[red] value is successfully overridden to dog.
https://gist.github.com/3684847 (override_array_defaults.cf)
cf-agent -KIf ./override_array_defaults.cf
R: Why does local_array[blue] not get set from the param?
R:
R: Param: main.array[red]=dog
R: Param: main.array[blue]=fish
R:
R: Array: local_array[one]=fish
R: Array: local_array[two]=fish
R: Array: local_array[red]=dog
To me it looks like a bug.
body common control {
inputs => { "../sketches/CFEngine/stdlib/cfengine_stdlib.cf" };
bundlesequence => { "main" };
}
bundle agent main
{
vars:
"array[red]"
string => "dog",
policy => "free";
"array[blue]"
string => "fish",
policy => "free";
methods:
"story time" usebundle => test("main.array");
}
bundle agent test(prefix)
{
vars:
"local_array[one]"
string => "fish",
policy => "free";
"local_array[two]"
string => "fish",
policy => "free";
"local_array[red]"
string => "fish",
policy => "free";
"param_index" slist => getindices("$(prefix)");
# Override default values with those from parameter
"local_array[$(param_index)]"
handle => "test_vars_copy_paramaters_to_local_array",
string => "$($(prefix)[$(param_index)])",
policy => "free";
"array_keys" slist => getindices("local_array");
reports:
cfengine::
"Why does local_array[blue] not get set from the param?";
" ";
"Param: $(prefix)[$(param_index)]=$($(prefix)[$(param_index)])";
" ";
"Array: local_array[$(array_keys)]=$(local_array[$(array_keys)])";
}
body common control {
inputs => { "../sketches/CFEngine/stdlib/cfengine_stdlib.cf" };
bundlesequence => { "main" };
}
bundle agent main
{
vars:
"list" slist => {"id1", "id2", "id3"};
"local_array[$(list)]"
string => "value",
policy => "free";
reports:
cfengine::
"Array: local_array[$(list)]=$(local_array[$(list)])";
}
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine