# Querying AWX / automation controller

**URL:** <https://forum.ansible.com/t/querying-awx-automation-controller/281>\
**Category:** Guides, FAQs & Howtos\
**Tags:** documentation, awx\
**Created:** [September 6, 2023, 6:05pm UTC](https://forum.ansible.com/t/querying-awx-automation-controller/281 "2023-09-06T18:05:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IPvSean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ipvsean/32/1153_2.png) [@IPvSean](https://forum.ansible.com/u/IPvSean)\
**Post date:** [September 6, 2023, 6:05pm UTC](https://forum.ansible.com/t/querying-awx-automation-controller/281/1 "2023-09-06T18:05:33Z")

</div>

I am posting this because I usually have to play with this several times whenever this problem comes up. I am not sure how often this will come up for others… but hopefully this will save someone sometime in the future 🙂

There is an awesome Ansible content collection for AWX itself [Awx.Awx — Ansible Documentation](https://docs.ansible.com/ansible/latest/collections/awx/awx/index.html)

One of the Lookup Plugins there is very powerful: [awx.awx.controller\_api lookup – Search the API for objects — Ansible Documentation](https://docs.ansible.com/ansible/latest/collections/awx/awx/controller_api_lookup.html#ansible-collections-awx-awx-controller-api-lookup)

This will allow you to basically do any lookup in the API (which you can get to via https://your\_awx\_ip/api/v2)

Some of the documentation examples from the lookup plugin are great but they don’t contain a playbook so I thought I would show a very simple Ansible Playbook here that could run locally (on the AWX node itself).

```auto
---
- hosts: localhost
  vars: 
    desired_job_template: 'Network-Banner'
  tasks:
    - name: retrieve Network-Banner job template
      set_fact: 
        network_banner_exist: "{{ query('awx.awx.controller_api', 'job_templates', query_params={ 'name': desired_job_template }, host='localhost', username='admin', password='ansible123!', verify_ssl=False) }}"

    - name: print out network_banner_exist var
      debug: 
        msg: "{{ network_banner_exist }}"
      failed_when: network_banner_exist == []

    - name: fail when survey is not enabled
      debug: 
        msg: "Is a survey enabled for {{ desired_job_template }}? {{ network_banner_exist[0].survey_enabled }}"
      failed_when: not network_banner_exist[0].survey_enabled

```

This Ansible Playbook is (numbers corresponding to the tasks)

1. Queries the job\_templates, specifically looking for a job template called `desired_job_template`, which in my case is a job called `Network-Banner`
2. Will fail if this job is empty (which is `[]`) which means it does not exist.
3. Will fail if this job has no survey enabled.

This is a quick way to audit AWX / automation controller to make sure jobs exist, or are configured the way you want them.

I am showing usernames and passwords here, obviously you would want to encrypt those with something like `ansible-vault`.

---

<div class="post-metadata">

**Author:** ![samccann](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/samccann/32/18_2.png) [@samccann](https://forum.ansible.com/u/samccann)\
**Post date:** [September 6, 2023, 7:21pm UTC](https://forum.ansible.com/t/querying-awx-automation-controller/281/2 "2023-09-06T19:21:53Z")

</div>

is it worth adding the playbook to the docs? We have some community-writer volunteers that could probably just pop it in the docs if that seems helpful…

---

<div class="post-metadata">

**Author:** ![IPvSean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ipvsean/32/1153_2.png) [@IPvSean](https://forum.ansible.com/u/IPvSean)\
**Post date:** [September 6, 2023, 8:15pm UTC](https://forum.ansible.com/t/querying-awx-automation-controller/281/3 "2023-09-06T20:15:07Z")

</div>

Would be curious what others think, would certainly be cool to have more full playbook examples in the docs.
