# How to pass command line arg as input for dynamic-inventory executable program during ansible-playbook launch

**URL:** <https://forum.ansible.com/t/how-to-pass-command-line-arg-as-input-for-dynamic-inventory-executable-program-during-ansible-playbook-launch/20930>\
**Category:** Ansible Project\
**Created:** [March 20, 2016, 3:45am UTC](https://forum.ansible.com/t/how-to-pass-command-line-arg-as-input-for-dynamic-inventory-executable-program-during-ansible-playbook-launch/20930 "2016-03-20T03:45:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naren](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@Naren](https://forum.ansible.com/u/Naren)\
**Post date:** [March 20, 2016, 3:45am UTC](https://forum.ansible.com/t/how-to-pass-command-line-arg-as-input-for-dynamic-inventory-executable-program-during-ansible-playbook-launch/20930/1 "2016-03-20T03:45:03Z")

</div>

dynamic inventory can be achieved by

ansible-playbook -i dynamicInventory.py myplaybook.yml

in case I need to pass some dynamic input to the dynamicInventory.py program itself, how can I do that. Command line argument is not working when it coupled with ansible-playbook command

Any suggestions

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 20, 2016, 4:04am UTC](https://forum.ansible.com/t/how-to-pass-command-line-arg-as-input-for-dynamic-inventory-executable-program-during-ansible-playbook-launch/20930/2 "2016-03-20T04:04:53Z")

</div>

there is no way to do what you ask, options for dynamic inventory are set either in configuration files or environment variables.

---

<div class="post-metadata">

**Author:** ![Dejay\_Clayton](https://avatars.discourse-cdn.com/v4/letter/d/6de8d8/32.png) [@Dejay\_Clayton](https://forum.ansible.com/u/Dejay_Clayton)\
**Post date:** [March 20, 2016, 5:24am UTC](https://forum.ansible.com/t/how-to-pass-command-line-arg-as-input-for-dynamic-inventory-executable-program-during-ansible-playbook-launch/20930/3 "2016-03-20T05:24:32Z")

</div>

What operating system are you using to execute ansible-playbook?

---

<div class="post-metadata">

**Author:** ![Naren](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@Naren](https://forum.ansible.com/u/Naren)\
**Post date:** [March 20, 2016, 9:55am UTC](https://forum.ansible.com/t/how-to-pass-command-line-arg-as-input-for-dynamic-inventory-executable-program-during-ansible-playbook-launch/20930/4 "2016-03-20T09:55:41Z")

</div>

Ubuntu

---

<div class="post-metadata">

**Author:** ![Naren](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@Naren](https://forum.ansible.com/u/Naren)\
**Post date:** [March 20, 2016, 11:18am UTC](https://forum.ansible.com/t/how-to-pass-command-line-arg-as-input-for-dynamic-inventory-executable-program-during-ansible-playbook-launch/20930/5 "2016-03-20T11:18:38Z")

</div>

Environment variable kind of solution is good as long as I call my playbooks from console. But when it comes to automation by integrating with external systems; the inventory generator/builder should be good enough to pull inventory artifacts from database, REST APIs,…

All I need is something like

ansible-playbook -i dynamicInventory.py --script-args “location=chennai region=south” my\_playbook.yml

here ‘–script-args’ helps dyamicInventory.py program to pull inventory artifacts for specified location and region from some datastore

---

<div class="post-metadata">

**Author:** ![Benjamin\_Redling](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@Benjamin\_Redling](https://forum.ansible.com/u/Benjamin_Redling)\
**Post date:** [March 20, 2016, 11:49am UTC](https://forum.ansible.com/t/how-to-pass-command-line-arg-as-input-for-dynamic-inventory-executable-program-during-ansible-playbook-launch/20930/6 "2016-03-20T11:49:18Z")

</div>

What aspect of automation keeps you from setting environment variables?  
Where is the difference between calling from console and calling from a  
script?

E.g.,

SCRIPTARGS="location=chennai region=south" bash -c 'ansible-playbook -i  
dynamicInventory.py my\_playbook.yml'

When you evaluate SCRIPTARGS inside dynamicInventory.py I don't see  
where the difference is compared to your "--script-args" -- apart from  
the syntax.

Regards,  
Benjamin
