# Pull value from stdout

**URL:** <https://forum.ansible.com/t/pull-value-from-stdout/28341>\
**Category:** Ansible Developer\
**Created:** [August 16, 2018, 11:28am UTC](https://forum.ansible.com/t/pull-value-from-stdout/28341 "2018-08-16T11:28:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![email](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@email](https://forum.ansible.com/u/email)\
**Post date:** [August 16, 2018, 11:28am UTC](https://forum.ansible.com/t/pull-value-from-stdout/28341/1 "2018-08-16T11:28:27Z")

</div>

Hi

I am for some reason, really struggling to pull an item from stdout and register it.

Inside play:

1. 
  - debug:

2. msg: “{{ output.stdout }}”

Output:

1. ok: [localhost] =\> {

2. “msg”: {

3. “code”: 200,

4. “data”: “10.50.3.26”,

5. “success”: true,

6. “time”: 0.006

7. }

8. }

What I am looking to do is extract the ‘data’ item from the result.

I have tried {{ output.stdout[data] }} amongst other things but I just don’t seem to be able to get it going and Googling doesn’t seem to show what I’m after. I can only with with\_items elements.

Can anyone advise?

Thanks

---

<div class="post-metadata">

**Author:** ![Sumit\_Jaiswal](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@Sumit\_Jaiswal](https://forum.ansible.com/u/Sumit_Jaiswal)\
**Post date:** [August 16, 2018, 12:08pm UTC](https://forum.ansible.com/t/pull-value-from-stdout/28341/2 "2018-08-16T12:08:29Z")

</div>

Hi,

I believe you are not registering the output before filtering the key i.e. `data` in your case. You can try following:

```auto
- hosts: localhost
  tasks:
  - name: run Test task
    register: output

  - debug:
      data: “{{ output[’data'] }}"

```

Hope it helps.

**_Regards,_**  
Sumit

---

<div class="post-metadata">

**Author:** ![email](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@email](https://forum.ansible.com/u/email)\
**Post date:** [August 16, 2018, 12:19pm UTC](https://forum.ansible.com/t/pull-value-from-stdout/28341/3 "2018-08-16T12:19:27Z")

</div>

Hi Sumit,

The result is registered further up in the playbook which is where I’m getting the stdout values from.

But I’d to grab the IP address from the ‘data’ key in the debug msg and register that as a variable somehow to use elsewhere.

Thanks

---

<div class="post-metadata">

**Author:** ![Sumit\_Jaiswal](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@Sumit\_Jaiswal](https://forum.ansible.com/u/Sumit_Jaiswal)\
**Post date:** [August 16, 2018, 1:01pm UTC](https://forum.ansible.com/t/pull-value-from-stdout/28341/4 "2018-08-16T13:01:43Z")

</div>

Hi,

If you have already registered the **_output_** you can use _“set\_facts”_ module to filter the **ipaddress** from the **output** and then use the **_ipaddress_** and use in playbook as you want. For e.g.:

- hosts: localhost  
tasks:
- name: run Test task  
register: output
- debug:  
msg: “{{ output[’data’] }}” # this will just output the IP address
- name: get the data as ip  
set\_fact:  
ip: “{{ output[‘data’] }}”
- debug:  
msg: “{{ ip }}” # this will stdout the ip but can also be used as variable in play as well

Hope this will help.

Regards,  
Sumit
