Prototype: data_expand(data_container)

Return type: data

Description: Transforms a data container to expand all variable references.

This function will take a data container and expand variable references once in all keys and values.

[This function can accept many types of data parameters.][Functions#collecting functions]

Any compound (arrays or maps) data structures will be expanded recursively, so for instance data in a map inside another map will be expanded.

This function is chiefly useful if you want to read data from an external source and it can contain variable references.

Arguments:

  • data_container: string - CFEngine variable identifier or inline JSON - in the range: .*

Example:

Prepare to run the example policy:

echo '{ "$(main.x)": "$(main.y)" }' > /tmp/expand.json

Policy:

bundle agent main
{
  vars:
      "x" string => "the expanded x";
      "y" string => "the expanded y";

      "read" data => readjson("/tmp/expand.json", inf);
      "expanded" data => data_expand(read);

      "expanded_str" string => format("%S", expanded);

  reports:
      "$(this.bundle): the x and y references expanded to $(expanded_str)";
}

Output:

R: main: the x and y references expanded to {"the expanded x":"the expanded y"}

History: Was introduced in version 3.7.0 (2015). The [collecting functions][Functions#collecting functions] behavior was added in 3.9.

See also: [readcsv()](/reference/functions/readcsv “readcsv”), [readjson()](/reference/functions/readjson “readjson”), [readyaml()](/reference/functions/readyaml “readyaml”), [mergedata()](/reference/functions/mergedata “mergedata”), [readenvfile()](/reference/functions/readenvfile “readenvfile”), [classfiltercsv()](/reference/functions/classfiltercsv “classfiltercsv”), [about collecting functions][Functions#collecting functions], and data documentation.