# Group hosts by value from list object of inventory var

**URL:** <https://forum.ansible.com/t/group-hosts-by-value-from-list-object-of-inventory-var/18093>\
**Category:** Ansible Project\
**Created:** [April 27, 2015, 10:11am UTC](https://forum.ansible.com/t/group-hosts-by-value-from-list-object-of-inventory-var/18093 "2015-04-27T10:11:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mook](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@Mook](https://forum.ansible.com/u/Mook)\
**Post date:** [April 27, 2015, 10:11am UTC](https://forum.ansible.com/t/group-hosts-by-value-from-list-object-of-inventory-var/18093/1 "2015-04-27T10:11:00Z")

</div>

Hi.  
I have an inventory like this:

[test\_servers]  
192.168.0.101 app\_roles=‘[“relay\_master”]’  
192.168.0.102 app\_roles=‘[“relay\_slave”,“cache”,“web\_master”]’  
192.168.0.103 app\_roles=‘[“relay\_slave”,“cache”,“web\_slave”]’

Is it possible to add servers that, for example, have “cache” in their app\_roles to a group (like with group\_by)?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 27, 2015, 7:40pm UTC](https://forum.ansible.com/t/group-hosts-by-value-from-list-object-of-inventory-var/18093/2 "2015-04-27T19:40:25Z")

</div>

yes, but I find it easier to just create groups for that

[test\_servers]  
192.168.0.101

[relay\_masters]  
192.168.0.101  
10.10.1.101  
and then have the plays target the servers, using --limit to restrict  
to 'test\_servers':

- hosts: relay\_masters

or just make them separate inventories sharing group/host\_vars and  
choose with -i /inventories/testing

---

<div class="post-metadata">

**Author:** ![Mook](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@Mook](https://forum.ansible.com/u/Mook)\
**Post date:** [April 28, 2015, 9:14am UTC](https://forum.ansible.com/t/group-hosts-by-value-from-list-object-of-inventory-var/18093/3 "2015-04-28T09:14:33Z")

</div>

Came to the same conclusion. Thanks for confirming.
