# Connect to api ansible awx

**URL:** <https://forum.ansible.com/t/connect-to-api-ansible-awx/3717>\
**Category:** Get Help\
**Tags:** awx, collections, kubernetes\
**Created:** [February 6, 2024, 9:01pm UTC](https://forum.ansible.com/t/connect-to-api-ansible-awx/3717 "2024-02-06T21:01:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alvis9515](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alvis9515/32/1457_2.png) [@alvis9515](https://forum.ansible.com/u/alvis9515)\
**Post date:** [February 6, 2024, 9:01pm UTC](https://forum.ansible.com/t/connect-to-api-ansible-awx/3717/1 "2024-02-06T21:01:59Z")

</div>

Hello, I currently have ansible awx installed in kubernetes, I would like to know how to connect to the awx API?

for example connect to postman.

Regards;

---

<div class="post-metadata">

**Author:** ![Crimrose](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/crimrose/32/2239_2.png) [@Crimrose](https://forum.ansible.com/u/Crimrose)\
**Post date:** [February 7, 2024, 2:33am UTC](https://forum.ansible.com/t/connect-to-api-ansible-awx/3717/2 "2024-02-07T02:33:20Z")

</div>

You can follow this guide  
[https://docs.ansible.com/ansible-tower/latest/html/administration/oauth2\_token\_auth.html](https://docs.ansible.com/ansible-tower/latest/html/administration/oauth2_token_auth.html)

Second method,  
Export these env:

```auto
export CONTROLLER_PASSWORD='abcaxxxxxxx'
export CONTROLLER_USERNAME=awx
export CONTROLLER_HOST='https://awx-testing.com'

```

Then you can communicate with your cluster from CLI.

---

<div class="post-metadata">

**Author:** ![relrod](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/relrod/32/107_2.png) [@relrod](https://forum.ansible.com/u/relrod)\
**Post date:** [February 7, 2024, 12:55pm UTC](https://forum.ansible.com/t/connect-to-api-ansible-awx/3717/3 "2024-02-07T12:55:45Z")

</div>

There are docs on authenticating to the API here: [AWX API Reference — Ansible AWX community documentation](https://ansible.readthedocs.io/projects/awx/en/latest/rest_api/index.html)

And you can explore the actual endpoints and parameters they take by going to your AWX instance and looking at the /api/ endpoint in your browser and looking at the browsable API. The parameters should hopefully be pretty well documented, but of course feel free to ask (or submit a PR!) if something isn’t clear 🙂

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [February 8, 2024, 4:37pm UTC](https://forum.ansible.com/t/connect-to-api-ansible-awx/3717/4 "2024-02-08T16:37:08Z")

</div>

This works great, because then you can code your configuration into playbooks. This makes life a LOT easier if you need to wipe your AWX install and start over (lab, testing, etc.).

1. Install ansible-core (cli python version of ansible) to your local computer
2. Set those environment variables to the correct values  
Note: You can also set the values at runtime in the playbook if you do not want to worry about environment variables, as shown below.
3. Install the awx.awx ansible-galaxy collection
4. Write/Execute your playbooks to update your AWX installation.

Sample playbook create a couple inventories:

```yml
# Filename pb_inventories.yml
- name: ========== Configure Inventories ==========
  connection: local
  hosts: lab
  gather_facts: no
  environment:
    CONTROLLER_USERNAME: "{{ controller_username }}"
    CONTROLLER_PASSWORD: "{{ controller_password }}"
    CONTROLLER_HOST: "{{ awx_url }}"

  tasks:
    - name: A10 Dev
      awx.awx.inventory:
        name: A10 Dev
        description: Non-production A10s
        organization: Connectivity Services
        state: present

    - name: A10 Prod
      awx.awx.inventory:
        name: A10 Prod
        description: Production A10s
        organization: Connectivity Services
        state: present

    - name: AWXLab
      awx.awx.inventory:
        name: AWXLab
        description: Lab AWX Instances
        organization: Connectivity Services
        state: present

    - name: LocalHost
      awx.awx.inventory:
        name: localhost
        description: localhost for execution from the execution environment
        organization: Connectivity Services
        state: present

```
