Skip to content

Instantly share code, notes, and snippets.

@tjormola
Last active November 14, 2015 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjormola/821460ee6393c4afc79c to your computer and use it in GitHub Desktop.
Save tjormola/821460ee6393c4afc79c to your computer and use it in GitHub Desktop.
body common control
{
bundlesequence => { "datatest" };
}
body agent control
{
ifelapsed => 0;
}
bundle agent datatest
{
vars:
"data_with_list_of_strings" data => parsejson('{"key":["item1","item2"]}');
"data_with_list_of_maps" data => parsejson('{"key":[{"name":"item1"},{"name":"item2"}]}');
methods:
"handle_list_of_strings" usebundle => handle_list_of_strings(@(data_with_list_of_strings[key]));
"handle_list_of_maps" usebundle => handle_list_of_maps(@(data_with_list_of_maps[key]));
}
bundle agent handle_list_of_strings(list)
{
vars:
"list_str" string => format("%S", list);
methods:
# Bundle is applied for each item in the list
"handle_list_items" usebundle => handle_string_item($(list));
reports:
"$(this.bundle) called with list $(list_str)";
}
bundle agent handle_list_of_maps(list)
{
vars:
"list_str" string => format("%S", list);
methods:
# Bundle is not applied for each item in the list
"handle_list_items" usebundle => handle_map_item($(list));
reports:
"$(this.bundle) called with list $(list_str)";
}
bundle agent handle_string_item(item)
{
reports:
"$(this.bundle) called with item $(item)";
}
bundle agent handle_map_item(item)
{
vars:
"item_str" string => format("%S", item);
methods:
"handle_string_item" usebundle => handle_string_item($(item[name]));
reports:
"$(this.bundle) called with item $(item_str)";
}
@tjormola
Copy link
Author

(13:21:35)(tj@ganga)(~)$ cf-agent --version
CFEngine Core 3.8.0b1
(13:21:40)(tj@ganga)(~)$ cf-agent /tmp/datatest.cf 
R: handle_string_item called with item item1
R: handle_string_item called with item item2
R: handle_list_of_strings called with list ["item1","item2"]
R: handle_list_of_maps called with list [{"name":"item1"},{"name":"item2"}]
(13:21:43)(tj@ganga)(~)$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment