# How to query group membership in AWX?

**URL:** <https://forum.ansible.com/t/how-to-query-group-membership-in-awx/32679>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [April 14, 2020, 3:10pm UTC](https://forum.ansible.com/t/how-to-query-group-membership-in-awx/32679 "2020-04-14T15:10:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kamerynn](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@Kamerynn](https://forum.ansible.com/u/Kamerynn)\
**Post date:** [April 14, 2020, 3:10pm UTC](https://forum.ansible.com/t/how-to-query-group-membership-in-awx/32679/1 "2020-04-14T15:10:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kamerynn](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@Kamerynn](https://forum.ansible.com/u/Kamerynn)\
**Post date:** [April 15, 2020, 4:37pm UTC](https://forum.ansible.com/t/how-to-query-group-membership-in-awx/32679/2 "2020-04-15T16:37:45Z")

</div>

> 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
