# AWX: Dynamic inventory script using the value set in EXTRA\_VARS

**URL:** <https://forum.ansible.com/t/awx-dynamic-inventory-script-using-the-value-set-in-extra-vars/41651>\
**Category:** Get Help\
**Tags:** awx\
**Created:** [April 10, 2025, 10:26am UTC](https://forum.ansible.com/t/awx-dynamic-inventory-script-using-the-value-set-in-extra-vars/41651 "2025-04-10T10:26:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![javeedf](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/javeedf/32/8105_2.png) [@javeedf](https://forum.ansible.com/u/javeedf)\
**Post date:** [April 10, 2025, 10:26am UTC](https://forum.ansible.com/t/awx-dynamic-inventory-script-using-the-value-set-in-extra-vars/41651/1 "2025-04-10T10:26:12Z")

</div>

I am trying to generate inventory data based on instance\_id that will be given as a input as EXTRA\_VARS

```auto
ansible-inventory -i inventory/my_inventory.py --list -e "instance_id=198"

```

**url** = [https://api.myapp.com/id=](https://api.myapp.com/id=)\<instance\_id\>  
**sample url:** [https://api.myapp.com/id=198](https://api.myapp.com/id=198)

above URL shall give the list of hosts, using Dynamic inventory script  
1a. get the instance\_id from the EXTRA\_VARS, in this case its instance\_id and its value is 198  
1b. query the url mentioned above  
1c. Get the list of hosts  
1d. build the inventory data in JSON

I am stuck at point (1a) above on how to get the instance\_id into my Dynamic inventory script

how can I achieve this through dynamic inventory script? or please let me know any other way to achieve this

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [April 10, 2025, 4:05pm UTC](https://forum.ansible.com/t/awx-dynamic-inventory-script-using-the-value-set-in-extra-vars/41651/2 "2025-04-10T16:05:46Z")

</div>

inventory scripts do not get extra vars, only inventory plugins can and they need to invoke a specific option for that
