# Do dynamic inventories support command line arguments?

**URL:** <https://forum.ansible.com/t/do-dynamic-inventories-support-command-line-arguments/19628>\
**Category:** Ansible Project\
**Created:** [October 27, 2015, 3:12pm UTC](https://forum.ansible.com/t/do-dynamic-inventories-support-command-line-arguments/19628 "2015-10-27T15:12:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![george\_hartzell](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@george\_hartzell](https://forum.ansible.com/u/george_hartzell)\
**Post date:** [October 27, 2015, 3:12pm UTC](https://forum.ansible.com/t/do-dynamic-inventories-support-command-line-arguments/19628/1 "2015-10-27T15:12:35Z")

</div>

Hi All,  
At [http://docs.ansible.com/ansible/intro\_dynamic\_inventory.html](http://docs.ansible.com/ansible/intro_dynamic_inventory.html), about halfway down, there's an example that reads:

&nbsp;&nbsp;&nbsp;&nbsp;ansible-playbook -i 'ec2.py --profile prod' myplaybook.yml

which suggests that it's possible to pass arguments to dynamic inventory programs.

In real life, I can't seem to get it to work. Is the just a bad example or is there a trick that I'm missing?

Thanks,

g.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 27, 2015, 4:26pm UTC](https://forum.ansible.com/t/do-dynamic-inventories-support-command-line-arguments/19628/2 "2015-10-27T16:26:24Z")

</div>

That should not be possible. I would say that is a bad example.

---

<div class="post-metadata">

**Author:** ![esco\_real](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@esco\_real](https://forum.ansible.com/u/esco_real)\
**Post date:** [October 27, 2015, 5:13pm UTC](https://forum.ansible.com/t/do-dynamic-inventories-support-command-line-arguments/19628/3 "2015-10-27T17:13:06Z")

</div>

You could use some wrapper script(s) as inventory source for that…

---

<div class="post-metadata">

**Author:** ![Nirav\_Radia](https://avatars.discourse-cdn.com/v4/letter/n/90ced4/32.png) [@Nirav\_Radia](https://forum.ansible.com/u/Nirav_Radia)\
**Post date:** [September 8, 2016, 6:59am UTC](https://forum.ansible.com/t/do-dynamic-inventories-support-command-line-arguments/19628/4 "2016-09-08T06:59:50Z")

</div>

@esco real : The question remains the same. How to pass a command line argument to that wrapper script then?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 8, 2016, 3:48pm UTC](https://forum.ansible.com/t/do-dynamic-inventories-support-command-line-arguments/19628/5 "2016-09-08T15:48:23Z")

</div>

You don’t. As of now, the recommended way to provide configuration to an inventory script is either via configuration file, or via environment variables.

As of now, there is no way to pass arguments directly to a dynamic inventory script.

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [September 8, 2016, 4:13pm UTC](https://forum.ansible.com/t/do-dynamic-inventories-support-command-line-arguments/19628/6 "2016-09-08T16:13:31Z")

</div>

> As of now, the recommended way to provide configuration to an  
> inventory script is either via configuration file, or via environment  
> variables.
> 
> As of now, there is no way to pass arguments directly to a dynamic  
> inventory script.

We've done things like this by having a default 'hosts' wrapper script  
that calls our dynamic inventory script, and then other wrapper scripts  
that call the dynamic inventory script with arguments, so you can add  
'--inventory other-wrapper' or prefix 'ANSIBLE\_HOSTS=other-wrapper' to get  
the other wrapper, which passes along the command line argument.

If you want to be able to specify an arbitrary argument on the command  
line on the fly, that won't work; but if you've got a few typical  
command-line arguments you want to pass, something like this can work.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.
