-
Notifications
You must be signed in to change notification settings - Fork 12
Description
When running openstack commands (I was using server show action) if the output is in yaml format I attempt either
str( result() ) - or - '{{ result() | to_yaml_string }}' and I output this is a variable; however, I can not use
'{{ ctx().variable | from _yaml_string }}' to output this back to a json object, as it's throwing the following error.
"JinjaEvaluationException: Unable to evaluate expression '{{ ctx().variable | from_yaml_string }}'. ScannerError: mapping values are not allowed in this context\n in "", line 1, column 57"
if however, I send the yaml output to a file (action core.local command - server show > yaml.txt)
I'm able to "cat" the files contents and use '{{ result().stdout | from_yaml_string }}' and the output looks perfect.
Understood that I can output json instead of yaml from the original command; however, the json output does not provide access to the values within the object - for example (please ignore appropriate json formatting)
addresses = { network1: 1.1.1.1 network2: 2.2.2.2 etc...}
The object addresses just produces a long string of text that we need to parse through using regex
if I import from yaml I'm able to address sub-objects directly - for example
result().addresses.network1 = 1.1.1.1
result().addresses.network2 = 2.2.2.2
this would be much simpler to just reference the object directly as the network name never changes but openstack's output changes the order of the "networks" listed which make regex matching all the more difficult.
Certainly would welcome any guidance