# Variable combining several lists

**URL:** <https://forum.ansible.com/t/variable-combining-several-lists/14738>\
**Category:** Ansible Project\
**Created:** [March 10, 2014, 7:40am UTC](https://forum.ansible.com/t/variable-combining-several-lists/14738 "2014-03-10T07:40:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Mahemoff](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Michael\_Mahemoff](https://forum.ansible.com/u/Michael_Mahemoff)\
**Post date:** [March 10, 2014, 7:40am UTC](https://forum.ansible.com/t/variable-combining-several-lists/14738/1 "2014-03-10T07:40:14Z")

</div>

Is there any way to define a variable as being the combination of several lists. For example, define “database\_clients” as being the combination of all items in groups[‘app\_servers’] and groups[‘processors’]. I’d rather define it once rather than use with\_items in different places to combine them.

I looked at set\_fact ([http://docs.ansible.com/set\_fact\_module.html](http://docs.ansible.com/set_fact_module.html)), but don’t think it’s possible that way.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [March 10, 2014, 11:42am UTC](https://forum.ansible.com/t/variable-combining-several-lists/14738/2 "2014-03-10T11:42:06Z")

</div>

you can define in hosts file

[database\_clients:children]  
processors  
app\_servers

or in other ways groups[‘processors’]|union(groups[‘app\_servers’])

---

<div class="post-metadata">

**Author:** ![Michael\_Mahemoff](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Michael\_Mahemoff](https://forum.ansible.com/u/Michael_Mahemoff)\
**Post date:** [March 10, 2014, 2:52pm UTC](https://forum.ansible.com/t/variable-combining-several-lists/14738/3 "2014-03-10T14:52:06Z")

</div>

That works, thanks.
