# Clarification on how to use Registered Variables

**URL:** <https://forum.ansible.com/t/clarification-on-how-to-use-registered-variables/13689>\
**Category:** Ansible Project\
**Created:** [October 16, 2013, 4:52am UTC](https://forum.ansible.com/t/clarification-on-how-to-use-registered-variables/13689 "2013-10-16T04:52:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Jaynes](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Matt\_Jaynes](https://forum.ansible.com/u/Matt_Jaynes)\
**Post date:** [October 16, 2013, 4:52am UTC](https://forum.ansible.com/t/clarification-on-how-to-use-registered-variables/13689/1 "2013-10-16T04:52:54Z")

</div>

This confusion is probably due to me not being a python programmer. So, for any other non-python users, hopefully this thread will be helpful.

Re: [http://ansibleworks.com/docs/playbooks\_variables.html#registered-variables](http://ansibleworks.com/docs/playbooks_variables.html#registered-variables)

We see a variable registered:

register: foo\_result

But then when it’s used, we see:

when: foo\_result.rc == 5

This probably makes perfect sense to python guys, but as a rubyist, I had no idea what was going on here. Googling “python rc” etc was also fruitless.

So, after a quick twitter conversation with Michael DeHaan, it sounds like for any registered variables, you have to append either “.rc” or “.stdout” to the variable in order to use the registered variable. Is that true for all cases, or just for when it’s used as a conditional like in the example?

Thanks!  
Matt

P.S. Despite further googling, finding any useful documentation on Python’s “rc” method is proving elusive. Is there some canonical Python reference where I should look?

---

<div class="post-metadata">

**Author:** ![Jurgen\_Haas2](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@Jurgen\_Haas2](https://forum.ansible.com/u/Jurgen_Haas2)\
**Post date:** [October 16, 2013, 7:08am UTC](https://forum.ansible.com/t/clarification-on-how-to-use-registered-variables/13689/2 "2013-10-16T07:08:39Z")

</div>

I’m not a Python programmer either but from my understanding this is not a Python issue at all.

What happens is that foo\_result is an array of variables. This array contains keyed values for several components of the command line feedback and some of the keys are:

rc: this is the result code from the command executed  
stdout: this contains the output to the standard output from the command executed. Often this is again an array of lines.  
stderr: like stdout but for the standard error output

There are many more and you can make them visible when you execute your playbook with the command line parameter -vvv, then you can see all included stuff in that variable.

---

<div class="post-metadata">

**Author:** ![Matt\_Jaynes](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Matt\_Jaynes](https://forum.ansible.com/u/Matt_Jaynes)\
**Post date:** [October 16, 2013, 7:48am UTC](https://forum.ansible.com/t/clarification-on-how-to-use-registered-variables/13689/3 "2013-10-16T07:48:09Z")

</div>

Very helpful! Thanks Jürgen!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 16, 2013, 12:54pm UTC](https://forum.ansible.com/t/clarification-on-how-to-use-registered-variables/13689/4 "2013-10-16T12:54:08Z")

</div>

Here’s a tip.

When you register something, run that playbook with “-v” and you can see all that is registered in the hash/dictionary – it’s actually usually _not_ an array.

- shell: /usr/bin/foo  
register: foo

If you run with “-v” you will see all of the values of the subelements.

In 1.4, it’s also super easy to do this:

- shell: /usr/bin/foo  
register: foo

- debug: var=foo

But if you are running an earlier version, you have to do:

- debug: msg=“the value of foo is {{ foo }}”

Foo will contain many more things than rc and stdout.

It’s on our list to make sure the documentation for each module shows all the attributes it returns so you don’t have to run “-v” or use “debug” to look, though I will say in all fairness this may not be immediately accomplished.

---

<div class="post-metadata">

**Author:** ![Matt\_Jaynes](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Matt\_Jaynes](https://forum.ansible.com/u/Matt_Jaynes)\
**Post date:** [October 16, 2013, 2:37pm UTC](https://forum.ansible.com/t/clarification-on-how-to-use-registered-variables/13689/5 "2013-10-16T14:37:14Z")

</div>

Great to know, I have a much better understanding now. Thanks!
