# Is there any way to get parsed data from stdout of each task on playbook?

**URL:** <https://forum.ansible.com/t/is-there-any-way-to-get-parsed-data-from-stdout-of-each-task-on-playbook/14803>\
**Category:** Ansible Project\
**Created:** [March 19, 2014, 4:47am UTC](https://forum.ansible.com/t/is-there-any-way-to-get-parsed-data-from-stdout-of-each-task-on-playbook/14803 "2014-03-19T04:47:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jinsik\_Kim](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@Jinsik\_Kim](https://forum.ansible.com/u/Jinsik_Kim)\
**Post date:** [March 19, 2014, 4:47am UTC](https://forum.ansible.com/t/is-there-any-way-to-get-parsed-data-from-stdout-of-each-task-on-playbook/14803/1 "2014-03-19T04:47:35Z")

</div>

Hi,

I am a newbie in this wonderful tool Ansible.  
I made a playbook script to test it.

But I found that sometimes I need to parse the stdout of each task.

For instance

- name : run and get the result in JSON format on stdout  
shell : “/usr/local/something”  
register : result

Let’s see result.stdout

{u’name’:u’test1’, u’ipaddress’:‘xxx.xxx.xxx.xx’, u’pass’:‘asdfasfd’}

Can I extract these three elements(name, ipaddress, pass) from stdout and use it on another task?

I think lot of users experienced this issue because the return values(stdout) of tools are not simple sometimes

Even if I have a plan to make another Module I think it’s tough because I should pass the three elements.  
(Unfortunately I am not good at Python yet)

Thanks in advance!

-Justin

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 21, 2014, 12:29pm UTC](https://forum.ansible.com/t/is-there-any-way-to-get-parsed-data-from-stdout-of-each-task-on-playbook/14803/2 "2014-03-21T12:29:23Z")

</div>

You should be able to use that json by doing something like:

- debug: msg=“{{ (result.stdout|from\_json).ipaddress }}”

If you wanted to try to turn the whole thing into an accessible data type, you could probably use set\_fact:

- set\_fact:  
some\_new\_var: “{{ result.stdout|from\_json }}”

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 21, 2014, 1:09pm UTC](https://forum.ansible.com/t/is-there-any-way-to-get-parsed-data-from-stdout-of-each-task-on-playbook/14803/3 "2014-03-21T13:09:38Z")

</div>

Sort of. set\_fact doesn’t have anything to coerce string inputs and will result in you storing a string.

However, you can use {{ result.stdout | from\_json }} anywhere you want the datastructure.

---

<div class="post-metadata">

**Author:** ![Aviya\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@Aviya\_Singh](https://forum.ansible.com/u/Aviya_Singh)\
**Post date:** [May 7, 2019, 6:44am UTC](https://forum.ansible.com/t/is-there-any-way-to-get-parsed-data-from-stdout-of-each-task-on-playbook/14803/4 "2019-05-07T06:44:28Z")

</div>

Hi,

This was helpful.

Meanwhile, I am trying to extract “PRETTY NAME” in a loop from below output. What should I use?

 ![snip3.PNG](https://us1.discourse-cdn.com/ansible/original/2X/4/41c3e9fb4899f3951f00e6372df78c6a5d2a3260.png)

Can you look into this ?

---

<div class="post-metadata">

**Author:** ![tharun.kumarc09](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tharun.kumarc09](https://forum.ansible.com/u/tharun.kumarc09)\
**Post date:** [May 7, 2019, 4:42pm UTC](https://forum.ansible.com/t/is-there-any-way-to-get-parsed-data-from-stdout-of-each-task-on-playbook/14803/5 "2019-05-07T16:42:33Z")

</div>

You can use some thing like this.

- set\_fact:  
Name: (result.stdout | from\_json).name  
Ipaddress: similar to the above

> **(attachments)**
>
> ![snip3.PNG](https://us1.discourse-cdn.com/ansible/original/2X/4/41c3e9fb4899f3951f00e6372df78c6a5d2a3260.png)

---

<div class="post-metadata">

**Author:** ![Aviya\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@Aviya\_Singh](https://forum.ansible.com/u/Aviya_Singh)\
**Post date:** [May 7, 2019, 5:29pm UTC](https://forum.ansible.com/t/is-there-any-way-to-get-parsed-data-from-stdout-of-each-task-on-playbook/14803/6 "2019-05-07T17:29:03Z")

</div>

Thank you for the time.

I tried the Ipaddess parttern for my case. Also, tried the case suggested by you. But did not receive positive results.

Below is the snip of my code and the output respectively.

 ![1..PNG](https://us1.discourse-cdn.com/ansible/original/2X/7/7c283ab99dd82355e9b771e157ebafeb00b13b5a.png)

 ![2.PNG](https://us1.discourse-cdn.com/ansible/original/2X/3/3c47d1c70714c789d8b64802f759f30505b43836.png)

---

<div class="post-metadata">

**Author:** ![tharun.kumarc09](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@tharun.kumarc09](https://forum.ansible.com/u/tharun.kumarc09)\
**Post date:** [May 7, 2019, 9:46pm UTC](https://forum.ansible.com/t/is-there-any-way-to-get-parsed-data-from-stdout-of-each-task-on-playbook/14803/7 "2019-05-07T21:46:17Z")

</div>

![IMG_9953.jpg](https://us1.discourse-cdn.com/ansible/original/2X/2/2af3eea226424dc58451e10a9e924c37009786b2.jpeg)

U can use system-release instead of os-release if you are just trying find the os name and version from all hosts.

This should return something like this.

 ![Capture.PNG](https://us1.discourse-cdn.com/ansible/original/2X/c/c663d90906140705f3a57272ac203d333d84ba73.png)

> **(attachments)**
>
> ![1..PNG](https://us1.discourse-cdn.com/ansible/original/2X/7/7c283ab99dd82355e9b771e157ebafeb00b13b5a.png)  
> ![2.PNG](https://us1.discourse-cdn.com/ansible/original/2X/3/3c47d1c70714c789d8b64802f759f30505b43836.png)
