I am working on a playbook (for use in AWX) to handle some backend processing for one of our web apps.
One of the extra variables passed to the playbook via a REST call to AWX is used to pass the hosts
to the playbook
hosts: {{target}}
target can be a single server or a list of servers.
Question: how can I use patterns to skip a host if it is not a member of an inventory group
e.g if I want the playbook to skip a server if it's in the staging group in inventory
I have tried the following:
hosts: "{{target}}:!staging"
this only works if only one server is sent as target var, however it fails if called with a list.
This should work if you do use
:
as delimiter for your hosts and not,
.The syntax
host1:host2:host3:!staging
works, buthost1,host2,host3:!staging
, on the other hand, does generates a warningand this could well be the issue you are facing too.
The two syntaxes are documented here
Given the inventory:
And the playbook:
This yields the recap:
And it gives the exact same recap when using the playbook:
Run via: