Prototype: getvalues(varref)

Return type: slist

Description: Returns the list of values in varref which can be the name of an array or container.

This function can accept many types of data parameters.

If the array contains list values, then all of the list elements are flattened into a single list to make the return value a list.

If the data container contains non-scalar values (e.g. nested containers) they are skipped. The special values true, false, and null are serialized to their string representations. Numerical values are serialized to their string representations.

You can specify a path inside the container. For example, below you'll look at the values of d[k], not at the top level of d.

Make sure you specify the correct scope when supplying the name of the variable.


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


body common control
      bundlesequence => { "example" };

bundle agent example

      "v[index_1]" string => "value_1";
      "v[index_2]" string => "value_2";

      "values"        slist => getvalues("v");
      "values_sorted" slist => sort(values, lex);

      # works with data containers too
      "d" data => parsejson('{ "k": [ 1, 2, 3, "a", "b", "c" ] }');

      "cvalues"        slist => getvalues("d[k]");
      "cvalues_sorted" slist => sort(cvalues, lex);

      "Found values: $(values_sorted)";
      "Found container values: $(cvalues_sorted)";



R: Found values: value_1
R: Found values: value_2
R: Found container values: 1
R: Found container values: 2
R: Found container values: 3
R: Found container values: a
R: Found container values: b
R: Found container values: c

History: The collecting function behavior was added in 3.9.

See also: getindices(), about collecting functions, and data documentation.