How to query group membership in AWX?

Hi,

Just recently making the move from Ansible to Ansible AWX so excuse if this comes across as a daft question.

When trying to get some of my existing scripts to run from AWX i’m coming across a few issues which i’m sure is down to me missing something…
I have created the inventory manually and have a load of smart inventory groups to filter down the hosts to a subset of machines so we can run plays against a specific set.

Some of my scripts would check to see if the host is in a group before running the task. For example I have a script that stops certain services before shutting down a VM to make sure it is graceful.

  • name: stop elasticsearch services
    systemd:
    name: elasticsearch
    state: stopped
    ignore_errors: true
    when: “‘ElasticSearch-All’ in group_names”

So while this runs without error, it is not picking up that a machine is in fact a member of the group. In the results I would get {“changed”: false, “skip_reason”: “Conditional result was False”} even when the machine is in the group “ElasticSearch-All” in this example.

Have I just setup the groups incorrectly or do I need to alter the when clause to something else for AWX?

Thanks,

Kam

OK, I figured out where I was going wrong. Pure user error…

I had created an inventory “All” with all the hosts in our environment. Then I had created Smart Inventories to filter these down into ElasticSearch, MariaDB etc etc.
I was then using these Smart Inventory names in my query which obviously (now) was not classed as a group_name

I’ve re-created the inventories with groups under each one to split the hosts up and this is working as expected. So a bit more work setting up the necessary inventories to how we want them but at least it’s working.

Thanks,
Kam