Variable in JSON

14 views
Skip to first unread message

Alok Ranjan

unread,
Feb 13, 2017, 9:07:12 AM2/13/17
to Ansible Project
Dear All,

Can anyone please let me know how to use a register variable in JSON.

Where JSON is passed as an argument to a command using command module.

Any help or assistance would be highly appreciated.

Thanks,
Alok

Nehal J Wani

unread,
Feb 15, 2017, 7:11:15 AM2/15/17
to ansible...@googlegroups.com, iter...@gmail.com
Something like this should work:

[wani@linux tmp ]$ cat a.yaml
- hosts: localhost

tasks:
- command: 'echo {\"key\": \"value\"}'
register: my_output

- debug:
msg: "{{ my_output.stdout | from_json }}"


On, run, it will show:

TASK [debug] ********************************************************************************************************************************************************************************
task path: /tmp/a.yaml:7
ok: [localhost] => {
"changed": false,
"msg": {
"key": "value"
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/42641283-4ea2-43fe-941a-6c8bf4e548af%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Nehal J Wani
Reply all
Reply to author
Forward
0 new messages