# how to generate an iterable on with\_items with the attributes of a group's members ??

**URL:** <https://forum.ansible.com/t/how-to-generate-an-iterable-on-with-items-with-the-attributes-of-a-groups-members/21435>\
**Category:** Ansible Project\
**Created:** [May 13, 2016, 7:35pm UTC](https://forum.ansible.com/t/how-to-generate-an-iterable-on-with-items-with-the-attributes-of-a-groups-members/21435 "2016-05-13T19:35:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Comisario](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Alejandro\_Comisario](https://forum.ansible.com/u/Alejandro_Comisario)\
**Post date:** [May 13, 2016, 7:35pm UTC](https://forum.ansible.com/t/how-to-generate-an-iterable-on-with-items-with-the-attributes-of-a-groups-members/21435/1 "2016-05-13T19:35:15Z")

</div>

```auto
Hi guys, suppose i have this task like the one below, where i want all servers from the haproxy group to access a specific mysql database 

```

```auto

```

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 13, 2016, 7:56pm UTC](https://forum.ansible.com/t/how-to-generate-an-iterable-on-with-items-with-the-attributes-of-a-groups-members/21435/2 "2016-05-13T19:56:19Z")

</div>

I think I read that joining two lists (thats what they are) is done  
using a plus sign:

with\_items: groups['haproxy'] + groups['foobar']

In your case you do not have a second list foobar, you want to iterate  
over the first list but get another item, not the name that is in the  
inventory (ansible\_hostname) but something else. I do not know if that  
is possible.

Johannes

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 13, 2016, 9:24pm UTC](https://forum.ansible.com/t/how-to-generate-an-iterable-on-with-items-with-the-attributes-of-a-groups-members/21435/3 "2016-05-13T21:24:52Z")

</div>

I don't think you can do this in one task since host: need to have to different values.

So split in two tasks, one with

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host: "{{ item }}"  
&nbsp;&nbsp;&nbsp;with\_items: groups['haproxy']

and the second with

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host: "{{ hostvars[item]['ansible\_fqdn'] }}"  
&nbsp;&nbsp;&nbsp;with\_items: groups['haproxy']
