fwiw, there is 'parse_yaml_array', in tools/ds-identify, which does better (at least did not have this bug). Unfortunately that uses functions 'trim' and 'unquote', so you can't just grab the single function.
Second option would be to first *try* to use a proper yaml parser (python). There are some rules about not using dependencies in a config script I think (only essential maybe?). Thats why we don't use cloudinit infra to load it. So you can't *depend* on python and yaml but you could try.
Here is an example that could be added to your suggested fix:
try_python_yaml() {
# try to load something like 'datasource_list: [xxx]' and write space delimeted
# values to stdout
local py out="" fname="$1"
command -v python3 >/dev/null || return
out=$(python3 -c '
import yaml, sys;
print(",".join(yaml.load(sys.stdin.read()).get("datasource_list")))' \
< "$fname"
) || return
echo "$out"
}
fwiw, there is 'parse_yaml_array', in tools/ds-identify, which does better (at least did not have this bug). Unfortunately that uses functions 'trim' and 'unquote', so you can't just grab the single function.
Second option would be to first *try* to use a proper yaml parser (python). There are some rules about not using dependencies in a config script I think (only essential maybe?). Thats why we don't use cloudinit infra to load it. So you can't *depend* on python and yaml but you could try.
Here is an example that could be added to your suggested fix:
try_python_yaml() { ,".join( yaml.load( sys.stdin. read()) .get("datasourc e_list" )))' \
# try to load something like 'datasource_list: [xxx]' and write space delimeted
# values to stdout
local py out="" fname="$1"
command -v python3 >/dev/null || return
out=$(python3 -c '
import yaml, sys;
print("
< "$fname"
) || return
echo "$out"
}