# Register shell output in a variable

**URL:** <https://forum.ansible.com/t/register-shell-output-in-a-variable/21384>\
**Category:** Ansible Project\
**Created:** [May 9, 2016, 12:53pm UTC](https://forum.ansible.com/t/register-shell-output-in-a-variable/21384 "2016-05-09T12:53:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivo\_Hechmann](https://avatars.discourse-cdn.com/v4/letter/i/91b2a8/32.png) [@Ivo\_Hechmann](https://forum.ansible.com/u/Ivo_Hechmann)\
**Post date:** [May 9, 2016, 12:53pm UTC](https://forum.ansible.com/t/register-shell-output-in-a-variable/21384/1 "2016-05-09T12:53:15Z")

</div>

Hello team ansible

How can I register the output of a script in a variable? Thus, not the script result object with all its attributes like stdout, stderr etc, but only catch the stdout and register as variable?

Thank you very much for any hints…

Ivo

---

<div class="post-metadata">

**Author:** ![Petre\_Bandac](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@Petre\_Bandac](https://forum.ansible.com/u/Petre_Bandac)\
**Post date:** [May 9, 2016, 2:42pm UTC](https://forum.ansible.com/t/register-shell-output-in-a-variable/21384/2 "2016-05-09T14:42:56Z")

</div>

Register: ‘x’ = script.stdout or something? 🙂

Hab’s irgendwo gemacht, schicke dir morn ein Bispiu

Gruss 🙂

> **From:** Ivo Hechmann  
> **Sent:** Monday, May 9, 2016 14:53  
> **To:** Ansible Project  
> **Reply To:** [ansible-project@googlegroups.com](mailto:ansible-project@googlegroups.com)  
> **Subject:** [ansible-project] Register shell output in a variable  
>   
> |
> 
> - |

Hello team ansible

How can I register the output of a script in a variable? Thus, not the script result object with all its attributes like stdout, stderr etc, but only catch the stdout and register as variable?

Thank you very much for any hints…

Ivo

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [May 9, 2016, 2:48pm UTC](https://forum.ansible.com/t/register-shell-output-in-a-variable/21384/3 "2016-05-09T14:48:19Z")

</div>

You could use set\_fact to store just the stdout into another variable, but personally I wouldn’t bother - you can just ignore the bits of the register output that you don’t care about.

---

<div class="post-metadata">

**Author:** ![Ivo\_Hechmann](https://avatars.discourse-cdn.com/v4/letter/i/91b2a8/32.png) [@Ivo\_Hechmann](https://forum.ansible.com/u/Ivo_Hechmann)\
**Post date:** [May 10, 2016, 12:47pm UTC](https://forum.ansible.com/t/register-shell-output-in-a-variable/21384/4 "2016-05-10T12:47:44Z")

</div>

set\_fact did the trick. We have splitted our playbooks in roles. Depending on the job, the “version” variable is defined or undefined (but required, and can be retrieved by another script). With set\_fact I was able to define the variable as variable and not as task result.

Thank you  
ivo
