It turns out there is no need for unquoting.
In my original issue, the returned structure was much more complex and
included some strange *new lines*.
Removing all new lines with:
return.stdout | regex_replace('\\n', '')
solves this issue.
On Thursday, July 28, 2022 at 11:59:54 AM UTC+2 jean-christophe manciot
wrote:
> One shell command returns a json structure, but ansible converts it into a
> string in the registered variable.
> In order to access some attributes, this string needs to be unquoted, but
> how?
> There is a quote filter, but *there is no unquote filter in ansible or
> jinja2*.
>
> For instance, let's suppose a shell module returns the following
> registered variable:
> return:
> changed: true
> cmd: |-
> cmd_returning_json
> delta: '0:00:00.002283'
> end: '2022-07-28 11:09:17.921175'
> failed: false
> msg: ''
> rc: 0
> start: '2022-07-28 11:09:17.918892'
> stderr: ''
> stderr_lines: []
> stdout: '{"class": "data", "id":
> "a61b96e7-427e-493a-993c-c3efc8a16aa1", "size": "500GB", "type": "ssd"}'
>
> How do we convert return.stdout into:
> {"class": "data", "id": "a61b96e7-427e-493a-993c-c3efc8a16aa1", "size":
> "500GB", "type": "ssd"}
> so that we can access for instance:
> return.stdout.id
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/0e05fd79-b241-4ecb-935e-a24c823c47f8n%40googlegroups.com.