Running a playbook against group of hosts in AWX

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.

In the limit just use your group name?

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.

Ok try this.

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

In your playbook :

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 :frowning:

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.