# register: variable as {{item}}?

**URL:** <https://forum.ansible.com/t/register-variable-as-item/17746>\
**Category:** Ansible Project\
**Created:** [March 14, 2015, 7:19pm UTC](https://forum.ansible.com/t/register-variable-as-item/17746 "2015-03-14T19:19:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rick\_Kasten](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@Rick\_Kasten](https://forum.ansible.com/u/Rick_Kasten)\
**Post date:** [March 14, 2015, 7:19pm UTC](https://forum.ansible.com/t/register-variable-as-item/17746/1 "2015-03-14T19:19:13Z")

</div>

- shell: alternatives --display {{ item }} | grep “best” | grep “jre1.7.0\_75”  
sudo: yes  
register: “{{ item }}”  
ignore\_errors:  
with\_items:
- java
- javaws
- jcontrol

I’ve tried several iterations of this, all fail. Is there any way this can work? I don’t want to have to create 3 individual plays for each item. I have a much longer check coming up - like 25+ checks - and that will suck if I can’t do something like the above.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 14, 2015, 7:56pm UTC](https://forum.ansible.com/t/register-variable-as-item/17746/2 "2015-03-14T19:56:37Z")

</div>

What’s stopping you from registering this loop task with one variable? The iterated results get registered in a .results list .

---

<div class="post-metadata">

**Author:** ![Rick\_Kasten](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@Rick\_Kasten](https://forum.ansible.com/u/Rick_Kasten)\
**Post date:** [March 15, 2015, 4:55am UTC](https://forum.ansible.com/t/register-variable-as-item/17746/3 "2015-03-15T04:55:57Z")

</div>

Nothing’s stopping me. I don’t know what you’re referring to.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 15, 2015, 9:18am UTC](https://forum.ansible.com/t/register-variable-as-item/17746/4 "2015-03-15T09:18:23Z")

</div>

​I meant, don;t use the jinja variable construct on register, just a plain  
variable.  
A registered variable on with\_items will have a list of registered results.

Perhaps you need to to show us what you try to do with the registereed  
variable(s) later on.  
​

---

<div class="post-metadata">

**Author:** ![Rick\_Kasten](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@Rick\_Kasten](https://forum.ansible.com/u/Rick_Kasten)\
**Post date:** [March 15, 2015, 3:10pm UTC](https://forum.ansible.com/t/register-variable-as-item/17746/5 "2015-03-15T15:10:12Z")

</div>

I plan to run ‘alternatives --install {{ item }} yadayada’ for each in the list which will be only those items for which the above shell: command failed. I don’t want to run it against all three all the time. So are you saying that using a register: with multiple items will result in a list of register[item0].dict\_of\_variables, register[item1].dict\_of\_variables, etc?
