# ansible stdout

**URL:** <https://forum.ansible.com/t/ansible-stdout/21743>\
**Category:** Ansible Project\
**Created:** [June 11, 2016, 10:36pm UTC](https://forum.ansible.com/t/ansible-stdout/21743 "2016-06-11T22:36:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John.1209](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@John.1209](https://forum.ansible.com/u/John.1209)\
**Post date:** [June 11, 2016, 10:36pm UTC](https://forum.ansible.com/t/ansible-stdout/21743/1 "2016-06-11T22:36:50Z")

</div>

Is there a way to extract stdout variables from Ansible?

Here is my script:

- hosts: myhost  
sudo: yes  
tasks:

- name: output bash  
command: rpm -q bash  
register: result

- debug: msg=“{{ result.stderr }}”

Here is the output:

[root@ansi playbooks]$ ansible-playbook which\_bash.yml

PLAY [myhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [myhost]

TASK [which bash RPM] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [myhost]  
[WARNING]: Consider using yum module rather than running rpm

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [myhost] =\> {  
“bash\_version”: {  
“changed”: true,  
“cmd”: [  
“rpm”,  
“-q”,  
“bash”  
],  
“delta”: “0:00:00.045905”,  
“end”: “2016-06-11 18:22:07.782431”,  
“rc”: 0,  
“start”: “2016-06-11 18:22:07.736526”,  
“stderr”: “”,  
“stdout”: “bash-4.2.46-12.el7.x86\_64”,  
“stdout\_lines”: [  
“bash-4.2.46-12.el7.x86\_64”  
],  
“warnings”: [  
“Consider using yum module rather than running rpm”  
]  
}  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
myhost : ok=3 changed=1 unreachable=0 failed=0

The output works great. However I’m looking or a way to only extract the stdout from that output. I want nothing but stdout. How can I do that?

thanks in advance.

---

<div class="post-metadata">

**Author:** ![John\_Buxton](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@John\_Buxton](https://forum.ansible.com/u/John_Buxton)\
**Post date:** [June 12, 2016, 6:18pm UTC](https://forum.ansible.com/t/ansible-stdout/21743/2 "2016-06-12T18:18:54Z")

</div>

I’m not convinced your output matches your playbook.

Are you sure you’re running it correctly ?

Your output:

`TASK [debug] ******************************************************************* ok: [myhost] => { "bash_version": { etc...`

… implies you are using the debug module with a variable called bash\_version, e.g.  
`

- name: output bash  
command: rpm -q bash  
register bash\_version

- debug: var=bash\_version  
`

Which is not the same as the playbook you’ve quoted.

BTW, to get the stdout, you are nearly correct.

Use:

`

- debug: msg=“{{ result.stdout }}”  
`
