# Running a playbook against group of hosts in AWX

**URL:** <https://forum.ansible.com/t/running-a-playbook-against-group-of-hosts-in-awx/35610>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [August 11, 2021, 1:22pm UTC](https://forum.ansible.com/t/running-a-playbook-against-group-of-hosts-in-awx/35610 "2021-08-11T13:22:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GXW\_Online](https://avatars.discourse-cdn.com/v4/letter/g/919ad9/32.png) [@GXW\_Online](https://forum.ansible.com/u/GXW_Online)\
**Post date:** [August 11, 2021, 1:22pm UTC](https://forum.ansible.com/t/running-a-playbook-against-group-of-hosts-in-awx/35610/1 "2021-08-11T13:22:30Z")

</div>

Hi,

I’ve been using ansible for quite a while and have lots of playbooks that I run from the command line. I have an inventory with several groups in it. When I run a playbook I can tell it to run against a single host, or an inventory group, or a host pattern, or any combination thereof. So I might use this technique to run a playbook against a test server first, then the UAT group, and later the PROD group.

Now I’m trying to move my work into AWX, and have imported my inventory and playbooks using a git source.  
I found a way to select an inventory group and then “Run Command” against that group which is OK for ad-hoc stuff, but there doesn’t seem to be a way I can run playbooks against an inventory group.

Does anyone know if this is possible?

The closest I got is by using a survey in my template - and ask what hosts to run against, and feed the answer through to a variable which I pass into the hosts: statement.

This does work but I have to manually code every possible answer for a multiple choice question, which means I’ll have to modify all my surveys every time I add or change an inventory group.

The other option is a text answer to the survey but that means I have to validate every answer in my playbook somehow.

What I would like to do is have a survey that asks what group to run against, and automatically shows a list of groups in the active inventory - I know AWX can do this because it does it in the inventory hosts tab - but I would like to have this functionality in a survey.

Does anyone know if that can be done?

I also tried using “Limit” but that works on a host pattern and not all my groupings can be achieved with a host pattern - I just want to use the groups as already defined in the inventory.

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [August 11, 2021, 3:35pm UTC](https://forum.ansible.com/t/running-a-playbook-against-group-of-hosts-in-awx/35610/2 "2021-08-11T15:35:05Z")

</div>

In the limit just use your group name?

---

<div class="post-metadata">

**Author:** ![GXW\_Online](https://avatars.discourse-cdn.com/v4/letter/g/919ad9/32.png) [@GXW\_Online](https://forum.ansible.com/u/GXW_Online)\
**Post date:** [August 12, 2021, 8:52am UTC](https://forum.ansible.com/t/running-a-playbook-against-group-of-hosts-in-awx/35610/3 "2021-08-12T08:52:59Z")

</div>

Thanks for the suggestion. I tested that and whilst it does actually work, in that my playbook was restricted to running on the hosts in the group I specified in the Limit prompt, I’m not comfortable with that as a solution for a couple of reasons; 1) Limit is plain text so there is no validation of the input, and no restricting it to valid groups, 2) In order for Limit to work I need to set host: all in the playbook and I’m reluctant to do that because there is a risk that the playbook could be run accidentally against e.g. PROD. Also, if I’m using Limit to select the group I might as well just use the Survey to set the group in plain text, but neither of these let me do what I really want to do which is select the group from a dropdown.

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [August 12, 2021, 8:57am UTC](https://forum.ansible.com/t/running-a-playbook-against-group-of-hosts-in-awx/35610/4 "2021-08-12T08:57:48Z")

</div>

Ok try this.

Create a var in the hosts column. Say ‘node’ them do a survey to point to that.

In your playbook :

---

<div class="post-metadata">

**Author:** ![GXW\_Online](https://avatars.discourse-cdn.com/v4/letter/g/919ad9/32.png) [@GXW\_Online](https://forum.ansible.com/u/GXW_Online)\
**Post date:** [August 12, 2021, 10:29am UTC](https://forum.ansible.com/t/running-a-playbook-against-group-of-hosts-in-awx/35610/5 "2021-08-12T10:29:59Z")

</div>

Yes, thanks, that’s what I was referring to in my original post when I said “The closest I got is …” but does have some limitations. Probably best I can do with AWX ☹

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [August 12, 2021, 10:33am UTC](https://forum.ansible.com/t/running-a-playbook-against-group-of-hosts-in-awx/35610/6 "2021-08-12T10:33:36Z")

</div>

What you are really looking for is a form of logic in Choosing the limit. If that’s the case then I think you are right. The best bet is to have another ui maybe like rundeck? Then pass your parameters to it. That system will have logic/through script that will pass to ansible /awx.
