AWX - Create dynamic inventory from python script

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

I would start here:

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.
1 Like

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 :slight_smile:

Thanks,
Matt

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.

1 Like

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

1 Like