Running a playbook against group of hosts in AWX

1,796 views
Skip to first unread message

GXW Online

unread,
Aug 11, 2021, 9:22:30 AM8/11/21
to AWX Project
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.

Wei-Yen Tan

unread,
Aug 11, 2021, 11:35:18 AM8/11/21
to GXW Online, AWX Project
In the limit just use your group name?

From: 'GXW Online' via AWX Project <awx-p...@googlegroups.com>
Sent: Thursday, August 12, 2021 1:22:30 AM
To: AWX Project <awx-p...@googlegroups.com>
Subject: [awx-project] Running a playbook against group of hosts in AWX
 
--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/58a69b1f-868d-4781-9dc7-3ac55f5d874dn%40googlegroups.com.

GXW Online

unread,
Aug 12, 2021, 4:52:59 AM8/12/21
to AWX Project
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. 

Wei-Yen Tan

unread,
Aug 12, 2021, 4:57:57 AM8/12/21
to GXW Online, AWX Project
Ok try this. 

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

In your playbook :

---
- name: example 
  hosts : "{{ nodes}}"
  Roles:

    - example_role 



Then in your survey create a drop down with your limited group /hostname then put the variable as node.

From: 'GXW Online' via AWX Project <awx-p...@googlegroups.com>
Sent: Thursday, August 12, 2021 8:52:59 PM
To: AWX Project <awx-p...@googlegroups.com>
Subject: Re: [awx-project] Running a playbook against group of hosts in AWX
 

GXW Online

unread,
Aug 12, 2021, 6:29:59 AM8/12/21
to AWX Project
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 :-( 

Wei-Yen Tan

unread,
Aug 12, 2021, 6:33:47 AM8/12/21
to GXW Online, AWX Project
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. 

From: 'GXW Online' via AWX Project <awx-p...@googlegroups.com>
Sent: Thursday, August 12, 2021 10:29:59 PM
Reply all
Reply to author
Forward
0 new messages