I have a cert creation tool that outputs certs like so:
{
"cert": "abc123......",
"id": 10,
"key": "abc123....."
}
The actual cert and key attributes are base64 encoded but that's irrelevant to the problem here.
When I run this from ansible and register the output as a variable, it is stored with the double-quotes escaped:
{
"cert_output": {
"changed": true,
"delta": "0:00:00.673537",
"end": "2024-05-14 13:34:45.492559",
"failed": false,
"msg": "",
"rc": 0,
"start": "2024-05-14 13:34:44.819022",
"stderr": "",
"stderr_lines": [],
"stdout": "{\"id\":233370662,\"cert\":\"abc123...\",\"key\":\"abc123...\"}",
}
}
I do not find the way to parse out individual keys.
The two flavour of set_fact below are not working as intended:
- set_fact:
cert: "{{ cert_output.stdout|from_json|json_query('.cert') }}"
key: "{{ cert_output.stdout|from_json|json_query('.key') }}"
- set_fact:
cert: "{{ cert_output.stdout|json_query('.cert') }}"
key: "{{ cert_output.stdout|json_query('.key') }}"
Ansible error:
FAILED! => {"msg": "JMESPathError in json_query filter plugin:\ninvalid token: Parse error at column 0, token "." (DOT), for expression:\n".cert"\n ^"}