# How to use groups and/or labels in templates

**URL:** <https://forum.ansible.com/t/how-to-use-groups-and-or-labels-in-templates/38421>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [September 11, 2023, 9:53am UTC](https://forum.ansible.com/t/how-to-use-groups-and-or-labels-in-templates/38421 "2023-09-11T09:53:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bofh33](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@bofh33](https://forum.ansible.com/u/bofh33)\
**Post date:** [September 11, 2023, 9:53am UTC](https://forum.ansible.com/t/how-to-use-groups-and-or-labels-in-templates/38421/1 "2023-09-11T09:53:47Z")

</div>

Hello AWX-experts,

I have defined a huge list of hosts as an inventory. Now, I’d like to run some playbooks to a sub-group of them, i. e., the database hosts.  
So, I’ve defined a group “databases” below the main group, and would like to use this in my template - but, I can only choose the complete inventory without any option to choose the group.  
My next idea was to use labels, and attach a label “database” to all DB hosts or the subgroup - but that’s also not possible, labels can only be used for templates and inventories, if I’m right.  
So I’m a bit confused, is there any way to achieve this? Or do I have to create a new inventory containing only the database hosts and run my job against this?

Thanks and best regards from Germany,

Harald

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [September 11, 2023, 10:55am UTC](https://forum.ansible.com/t/how-to-use-groups-and-or-labels-in-templates/38421/2 "2023-09-11T10:55:07Z")

</div>

See the --limit option.

Walter

---

<div class="post-metadata">

**Author:** ![bofh33](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@bofh33](https://forum.ansible.com/u/bofh33)\
**Post date:** [September 11, 2023, 11:28am UTC](https://forum.ansible.com/t/how-to-use-groups-and-or-labels-in-templates/38421/3 "2023-09-11T11:28:21Z")

</div>

Hello Walter,

thanks for your answer. And yes, I’m using the --limit parameter on CLI and sometimes also in AWX to let a playbook run on only some hosts.  
But, I’d suppose that it would be possible to choose the defined labels and/or groups in job templates using the UI, as I can do it for inventories etc. Do I really have to write them in the limit field, as I do on CLI?

Thanks and best regards from Germany,

Harald

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [September 11, 2023, 11:59am UTC](https://forum.ansible.com/t/how-to-use-groups-and-or-labels-in-templates/38421/4 "2023-09-11T11:59:32Z")

</div>

Yes. I have Ansible Automation Platform. It has a limits field. We use that to “limit” which groups or hosts from the inventory are run against.

Walter
