Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Created November 8, 2022 14:30
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 nickanderson/286eb0a04c45df231e20f9a2ce4fc957 to your computer and use it in GitHub Desktop.
Save nickanderson/286eb0a04c45df231e20f9a2ce4fc957 to your computer and use it in GitHub Desktop.
Example illustrating munging YAML data structure into a list of strings

Example illustrating munging YAML data structure into a list of strings

bundle agent main
{
  vars:
      "yaml" data => parseyaml ('
  books:
    scifi_schema:
      isbn: "isbn_scifi"
      book_name: "book_name_scifi"
    travel_schema:
      isbn: "isbn_travel"
      book_name: "book_name_travel"
');

      "schemas" slist => getindices( "@(yaml[books])" );

      # Munge the data structure into a unified list of strings
      "arr_munged[$(schemas)]"
        string => "$(with)::isbn: '$(yaml[books][$(schemas)][isbn])' with book_name: '$(yaml[books][$(schemas)][book_name])'",
        with => regex_replace( "$(schemas)", "_schema", "", "g" );
      "l_munged" slist => getvalues( arr_munged );

  reports:

      "CFEngine '$(sys.cf_version)'";
      "$(l_munged)";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment