Is it possible to pass arguments to an inventory script?

670 views
Skip to first unread message

MarcG

unread,
Mar 13, 2018, 3:34:26 AM3/13/18
to AWX Project
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

Alan Rominger

unread,
Mar 13, 2018, 7:40:22 AM3/13/18
to MarcG, AWX Project
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


Alan
github: AlanCoding


--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project+unsubscribe@googlegroups.com.
To post to this group, send email to awx-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/1d1bddb5-4715-4fd3-9042-f796d165b20a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Jones

unread,
Mar 13, 2018, 3:42:07 PM3/13/18
to Alan Rominger, MarcG, AWX Project
There are also inventory source options that can be set and are available as an input box when setting up the inventory source.


For more options, visit https://groups.google.com/d/optout.



--
Matt Jones
Principal Software Engineer
Ansible Tower

MarcG

unread,
Mar 18, 2018, 5:06:12 AM3/18/18
to AWX Project
Thank you both very much for the detailed response.

Andrew Crisp

unread,
Apr 26, 2018, 6:43:54 AM4/26/18
to AWX Project
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

On Tuesday, March 13, 2018 at 7:42:07 PM UTC, Matthew Jones wrote:
There are also inventory source options that can be set and are available as an input box when setting up the inventory source.
On Tue, Mar 13, 2018 at 7:40 AM, Alan Rominger <arom...@redhat.com> wrote:
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


Alan
github: AlanCoding

On Tue, Mar 13, 2018 at 3:34 AM, MarcG <m...@marcosg.com> wrote:
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

--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project...@googlegroups.com.

To post to this group, send email to awx-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/1d1bddb5-4715-4fd3-9042-f796d165b20a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project...@googlegroups.com.

To post to this group, send email to awx-p...@googlegroups.com.

Ken P

unread,
Sep 3, 2022, 3:56:37 PM9/3/22
to AWX Project
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?

Reply all
Reply to author
Forward
0 new messages