# Can ansible dynamic inventory accept arguments ?

**URL:** <https://forum.ansible.com/t/can-ansible-dynamic-inventory-accept-arguments/18232>\
**Category:** Ansible Project\
**Created:** [May 14, 2015, 6:30pm UTC](https://forum.ansible.com/t/can-ansible-dynamic-inventory-accept-arguments/18232 "2015-05-14T18:30:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ritesh\_Shetty](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Ritesh\_Shetty](https://forum.ansible.com/u/Ritesh_Shetty)\
**Post date:** [May 14, 2015, 6:30pm UTC](https://forum.ansible.com/t/can-ansible-dynamic-inventory-accept-arguments/18232/1 "2015-05-14T18:30:22Z")

</div>

Hello !  
I have read through some forum posts that i could use env variables but i really do not want to do so. So wanted to know if ansible dynamic inventory can accept a variable

Ritesh

---

<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:** [May 14, 2015, 6:43pm UTC](https://forum.ansible.com/t/can-ansible-dynamic-inventory-accept-arguments/18232/2 "2015-05-14T18:43:25Z")

</div>

Dynamic inventory scripts only accept 2 arguments that ansible will actively attempt to call: --host and --list.

To provide additional configuration, your inventory script could have a config file, or utilize ENV vars as suggested in the other posts you have read.

---

<div class="post-metadata">

**Author:** ![Bob\_Brown](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@Bob\_Brown](https://forum.ansible.com/u/Bob_Brown)\
**Post date:** [May 15, 2015, 11:19pm UTC](https://forum.ansible.com/t/can-ansible-dynamic-inventory-accept-arguments/18232/3 "2015-05-15T23:19:41Z")

</div>

Not sure exactly what you mean by “accept arguments”.

You can do something like add the varible into the play book

hosts: ’ {{ hosts }}’

and then when you run the playbook you can say something like

ansible-playbook -e “hosts=HOSTNAME” playbook.yml  
OR better yet, use the inventory generated tag names lik  
ansible-playbook -e “hosts=tag\_Name\_cronbox-ops1-cronbox” playbook.yml

In “-e” you can add several value pairs that will act as variables.

Bob

---

<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:** [May 16, 2015, 3:29pm UTC](https://forum.ansible.com/t/can-ansible-dynamic-inventory-accept-arguments/18232/4 "2015-05-16T15:29:03Z")

</div>

don't use variables that overlap with keywords, use 'targets' instead  
of 'hosts', for example
