Is it possible to pass arguments to an inventory script?

Hi, I have written a inventory script written in Python, that I am using in AWX.

What I would like to do is pass some arguments to it some how to set some variables used within the script.

I know that AWX runs the script with the —list flag. Is there a way to pass other arguments to it from say a job template or elsewhere within AWX?

Many thanks

There is not an option to pass arguments directly, since Ansible itself does not allow this in any sense that I know of.

Instead, you can pass values through environment variables. This is the most common way that Ansible inventory scripts take inputs.

To do this in AWX, create a new credential type, and in here, define the environment variable structure you need. Then create a credential of this type. Then attach that credential to your inventory source. The script that runs should read from os.environ or something like that to take in the values. Here are some examples

https://github.com/AlanCoding/Ansible-inventory-file-examples/tree/master/scripts/environment

There are also inventory source options that can be set and are available as an input box when setting up the inventory source.

Thank you both very much for the detailed response.

Alan / Matthew - I’ve been pondering how to do this for scenario I am looking at.

we have a patching portal where users can assign their hosts to be patched in a particular slot. What we plan to then do is do a uri call to awx calling our patching job template and passing in the slot number. What I would like to do but can’t see how - is to then pass this slot number to the dynamic inventory script - so it can then go and retrieve the hosts for that slot. At moment the only thing I can think to do is retrieve ALL the hosts and their slots and use the slot number passed as a limit to the job template. However this could well be thousands of hosts so could well have performance impact retrieving them.

Any suggestions welcome.

Andy

i have to tag a question as this is closet i got to my problem.
our tower implementation in organization does not allow to create new “credential type”.
in that case, is there any trick to pass env variable to my inventory script via Tower Launch API?