bundlestate

Table of Contents

Prototype: bundlestate(bundlename)

Return type: data

Description: Returns the current evaluation data state for bundle bundlename.

The returned data container will have keys corresponding to the variables in bundle bundlename. The value is converted to a data container (JSON format) if necessary. So for example the variable x holding the CFEngine slist { "1", "a", "foo" } will be converted to the equivalent JSON array under the key x: "x": [ "1", "a", "foo" ].

Note: unlike datastate() classes are not collected.

The namespace of the bundle should not be included if it's in the default: namespace (all CFEngine bundles are, unless you override that). But if the bundle is in another namespace, you must prefix the name with the namespace in the normal mynamespace:mybundle fashion.

Arguments:

  • bundlename: string, in the range: [a-zA-Z0-9_$(){}\[\].:]+

Example:

body common control
{
      bundlesequence => { holder, test };
}

bundle common holder
{
  classes:
      "holderclass" expression => "any"; # will be global

  vars:
      "s" string => "Hello!";
      "d" data => parsejson('[4,5,6]');
      "list" slist => { "element1", "element2" };
}

bundle agent test
{
  vars:
      "bundle_state" data => bundlestate("holder");

      # all the variables in bundle "holder" defined as of the execution of bundlestate() will be here
      "holderstate" string => format("%S", "bundle_state");

  reports:
      "holder vars = $(holderstate)";
}

Output:

R: holder vars = {"d":[4,5,6],"list":["element1","element2"],"s":"Hello!"}

See also: getindices(), classesmatching(), variablesmatching(), mergedata(), template_method, mustache, inline_mustache, datastate()