Hello there!
I have been trying to brush some rust away from my CFEngine knowledge lately, and I've stumbled on a subject I had not become friends with: data containers. It looks to me that lists values behave like standard slists, but not quite, and I need your help.
I have a JSON file like this:
Basically, to each key I associate an object where the keys "sources" and "packages" are lists.
Now, if I iterate over those lists value in a string context, thus triggering implicit iteration, it works just fine, e.g. something like this works as expected:
vars:
"sw" data => readjson("software.json") ;
"swlist" slist => getindices("sw") ;
reports:
"${swname} packages: ${sw[${swname}][packages]}" ;
However, if I try to use the whole list as a parameter in a methods promise, I get a giant middle finger back. Something like this in bundle agent main:
# Ensure apt keys and sources
"ensure_${swname}_repo"
usebundle => add_apt_repo(
"${swname}",
"@{main.sw[${swname}][sources]}",
"${sw[${swname}][key]}",
"${henc.apt_keys_cachedir}",
"${refresh_apt_keys}",
"refresh_apt_cache"
),
if => "${sw[${swname}][trigger]}",
classes => classes_generic("${sw[${swname}][trigger]}_repo") ;
"install_${swname}"
usebundle => package_present("@{main.sw[$swname][packages]}"),
if => "${sw[${swname}][trigger]}",
classes => classes_generic("${sw[${swname}][trigger]}") ;
triggers this error:
R: [add_local_apt_key/files KEPT] Check apt key /var/cfengine/cache/apt-keys/azure-cli.gpg for changes
error: List or container parameter 'sources' not found while constructing scope 'add_apt_sourcefile' - use @(scope.variable) in calling reference
error: List or container parameter 'add_apt_sourcefile.repos_list' not found while constructing scope 'insert_lines' - use @(scope.variable) in calling reference
R: [add_apt_sourcefile/files KEPT] Ensure apt source azure-cli in /etc/apt/sources.list.d/azure-cli.list
error: List or container parameter 'main.sw[$swname][packages]' not found while constructing scope 'package_present' - use @(scope.variable) in calling reference
info: Installing @{main.sw[$swname][packages]}...
info: Q:env DEBIAN_FRONTEND= ...:E: Malformed line 1 in source list /etc/apt/sources.list.d/azure-cli.list (type)
info: Q:env DEBIAN_FRONTEND= ...:E: The list of sources could not be read.
info: Q:env DEBIAN_FRONTEND= ...:E: Malformed line 1 in source list /etc/apt/sources.list.d/azure-cli.list (type)
info: Q:env DEBIAN_FRONTEND= ...:E: The list of sources could not be read.
error: Finished command related to promiser '@{main.sw[$swname][packages]}' -- an error occurred, returned 100
error: Bulk package schedule execution failed somewhere - unknown outcome for '@{main.sw[$swname][packages]}'
R: [package_present/methods REPD] Ensure azure-cli is installed
The list is not dereferenced, the apt source gets corrupted and everything breaks.
I can see this is about dereferencing the list from the data container, but I am not sure how I should fix it to make it work. Using CFEngine 3.15.
Any help is appreciated!
Thanks, ciao!
-- bronto