# variables in with\_items:

**URL:** <https://forum.ansible.com/t/variables-in-with-items/13854>\
**Category:** Ansible Project\
**Created:** [November 6, 2013, 10:45am UTC](https://forum.ansible.com/t/variables-in-with-items/13854 "2013-11-06T10:45:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Angus1](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Paul\_Angus1](https://forum.ansible.com/u/Paul_Angus1)\
**Post date:** [November 6, 2013, 10:45am UTC](https://forum.ansible.com/t/variables-in-with-items/13854/1 "2013-11-06T10:45:35Z")

</div>

Hi all, can someone help me with a problem - I get some facts from my xenserver… the i want to use the version fact to get a list of required hotfixes i use:

with\_items:

- “${ansible\_xenserver\_version}-hotfixes”

to return “6.2.0-hotfixes”.

i want to use the items in that var list. but instead it just uses “6.2.0-hotfixes” as the item. How do i get ansible to use that as the pointer not an absolute value? similar to

with\_items:

- ${groups.xen-hosts}

group\_vars contains:

6.2.0-hotfixes:

- XS62E001
- XS62E002
- XS62E004

Many thanks

Paul Angus  
@CloudyAngus

---

<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:** [November 6, 2013, 2:02pm UTC](https://forum.ansible.com/t/variables-in-with-items/13854/2 "2013-11-06T14:02:07Z")

</div>

with\_items: groups.xen\_hosts

with\_items. groups[‘xen\_hosts’]

Don’t use legacy variables.

1.4 will warn you about these things.

---

<div class="post-metadata">

**Author:** ![Paul\_Angus1](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Paul\_Angus1](https://forum.ansible.com/u/Paul_Angus1)\
**Post date:** [November 6, 2013, 2:20pm UTC](https://forum.ansible.com/t/variables-in-with-items/13854/3 "2013-11-06T14:20:56Z")

</div>

Got it.  
…but what is the syntax of

with\_items:

- “{{ansible\_xenserver\_version}}-hotfixes”

to run through the groups\_vars

6.2.0-hotfixes

?

---

<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:** [November 8, 2013, 5:21pm UTC](https://forum.ansible.com/t/variables-in-with-items/13854/4 "2013-11-08T17:21:15Z")

</div>

Best practices would be to avoid performing variable name constructions programatically.

it would be better to store these in a hash and do

with\_items: hotfixes[ansible\_xenserver\_version]
