# AWX - Create dynamic inventory from python script

**URL:** <https://forum.ansible.com/t/awx-create-dynamic-inventory-from-python-script/43031>\
**Category:** Get Help\
**Tags:** awx, inventory\
**Created:** [May 27, 2025, 2:36pm UTC](https://forum.ansible.com/t/awx-create-dynamic-inventory-from-python-script/43031 "2025-05-27T14:36:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcoussi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mcoussi/32/8056_2.png) [@mcoussi](https://forum.ansible.com/u/mcoussi)\
**Post date:** [May 27, 2025, 2:36pm UTC](https://forum.ansible.com/t/awx-create-dynamic-inventory-from-python-script/43031/1 "2025-05-27T14:36:04Z")

</div>

Hi,

I use an AWX instance [23.7.0] with static inventory.

I developped a python script to create a dynamic inventory.  
The return is in YAML and works fine (Datasource from an API).

But now i want to create an inventory generated by exectued the python script.

Do you kno how can i do that ?

Thanks for your help,

Matt

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [May 27, 2025, 4:02pm UTC](https://forum.ansible.com/t/awx-create-dynamic-inventory-from-python-script/43031/2 "2025-05-27T16:02:57Z")

</div>

I would start here:

> **[Developing dynamic inventory — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html)**

In the end it comes down to 2 choices:

- turn it into an ‘inventory script’. It requires specific structure of JSON output.
- or turn it into an ‘inventory plugin’, no direct output, you now update the inventory objects directly, then use `ansible-inventory` to see the results.

---

<div class="post-metadata">

**Author:** ![mcoussi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mcoussi/32/8056_2.png) [@mcoussi](https://forum.ansible.com/u/mcoussi)\
**Post date:** [June 2, 2025, 6:48am UTC](https://forum.ansible.com/t/awx-create-dynamic-inventory-from-python-script/43031/3 "2025-06-02T06:48:05Z")

</div>

Hi @bcoca,  
Thanks for your reply.

It’s more complex for me currently.

So i decided to launch the python script manually te generate my inventories files and it works.

The next step is automatic but for the moment i’m not ready 🙂

Thanks,  
Matt

---

<div class="post-metadata">

**Author:** ![RaveoNmooN](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/raveonmoon/32/2583_2.png) [@RaveoNmooN](https://forum.ansible.com/u/RaveoNmooN)\
**Post date:** [June 6, 2025, 10:58am UTC](https://forum.ansible.com/t/awx-create-dynamic-inventory-from-python-script/43031/4 "2025-06-06T10:58:52Z")

</div>

Hi @mcoussi ,

You can create an inventory in AWX, and under the **Sources** tab, select the source type **“Sourced from a Project.”** Then, select your Python script (the dynamic inventory script you created) and ensure it runs within an appropriate AWX Execution Environment (EE) that contains all necessary Python packages. Make sure your script is executable in the repository so AWX can successfully run it after syncing your configured project.

Additionally, review the **Update options** in your source configuration and select what best suits your requirements. You can also configure an automatic schedule to ensure your dynamic inventory remains consistently up-to-date.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [June 6, 2025, 1:55pm UTC](https://forum.ansible.com/t/awx-create-dynamic-inventory-from-python-script/43031/5 "2025-06-06T13:55:30Z")

</div>

That still requires turning his current script into either an inventory plugin or inventory script

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 6, 2025, 1:56pm UTC](https://forum.ansible.com/t/awx-create-dynamic-inventory-from-python-script/43031/6 "2025-07-06T13:56:21Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
