# How configure Tower Template to use Dynamic Inventory Script.

**URL:** <https://forum.ansible.com/t/how-configure-tower-template-to-use-dynamic-inventory-script/30404>\
**Category:** Ansible Project\
**Created:** [May 23, 2019, 10:52am UTC](https://forum.ansible.com/t/how-configure-tower-template-to-use-dynamic-inventory-script/30404 "2019-05-23T10:52:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flavio\_Gobber](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@Flavio\_Gobber](https://forum.ansible.com/u/Flavio_Gobber)\
**Post date:** [May 23, 2019, 10:52am UTC](https://forum.ansible.com/t/how-configure-tower-template-to-use-dynamic-inventory-script/30404/1 "2019-05-23T10:52:16Z")

</div>

Hello Ansible Team,

I have written a Python script “inv-sched.py” which generates a JSON format inventory. This script is working using the command line ansible, with ansible command and ansible-playbook.  
Now I want to use this script through Tower manager, how can I configure a Template to use it ?.

Thank you for help.

Best regards.

Flavio Gobber

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [May 23, 2019, 12:05pm UTC](https://forum.ansible.com/t/how-configure-tower-template-to-use-dynamic-inventory-script/30404/2 "2019-05-23T12:05:16Z")

</div>

you can create a custom inventory script [https://docs.ansible.com/ansible-tower/latest/html/administration/custom\_inventory\_script.html](https://docs.ansible.com/ansible-tower/latest/html/administration/custom_inventory_script.html)

---

<div class="post-metadata">

**Author:** ![Flavio\_Gobber](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@Flavio\_Gobber](https://forum.ansible.com/u/Flavio_Gobber)\
**Post date:** [May 23, 2019, 12:19pm UTC](https://forum.ansible.com/t/how-configure-tower-template-to-use-dynamic-inventory-script/30404/3 "2019-05-23T12:19:36Z")

</div>

well, I have added my script to “Inventory Script”, but now, how can I use this script/Inventory in may “Template” for schedule a Playbook ?.  
Thank you

Flavio Gobber

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [May 23, 2019, 12:50pm UTC](https://forum.ansible.com/t/how-configure-tower-template-to-use-dynamic-inventory-script/30404/4 "2019-05-23T12:50:16Z")

</div>

dis you create an inventory and added a source that that gets the hosts? then on your job template there’s an inventory option to pick.

Jonathan Lozada De La Matta on mobile

– You received this message because you are subscribed to the Google Groups “Ansible Project” group. To unsubscribe from this group and stop receiving emails from it, send an email to . To post to this group, send email to . To view this discussion on the web visit . For more options, visit .

---

<div class="post-metadata">

**Author:** ![Flavio\_Gobber](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@Flavio\_Gobber](https://forum.ansible.com/u/Flavio_Gobber)\
**Post date:** [May 24, 2019, 8:34am UTC](https://forum.ansible.com/t/how-configure-tower-template-to-use-dynamic-inventory-script/30404/5 "2019-05-24T08:34:56Z")

</div>

Hello Jonathan,

I would show you with two screenshot what I have done and what I see on template page.

 ![InventoryScreenCapture.PNG](https://us1.discourse-cdn.com/ansible/original/2X/5/5b7152adfc677896ce12b15681833437d3625566.png)

 ![SelectInventoryScreenCapture.PNG](https://us1.discourse-cdn.com/ansible/original/2X/c/cbda3e26539a3f0f58082463d97bfacba71babfc.png)

The Inventory selection on Template configuration doesn’t show me to choose the script previus defined.

With the script showed above and ansible CLI the inventory works well.

Thank you

Beest regards

Flavio Gobber

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [May 24, 2019, 10:31am UTC](https://forum.ansible.com/t/how-configure-tower-template-to-use-dynamic-inventory-script/30404/6 "2019-05-24T10:31:25Z")

</div>

after you add the inventory script, you need to create an inventory. Once you create an inventory, you need to create a source. Please look at the documentation.

Jonathan Lozada De La Matta on mobile

– You received this message because you are subscribed to the Google Groups “Ansible Project” group. To unsubscribe from this group and stop receiving emails from it, send an email to . To post to this group, send email to . To view this discussion on the web visit . For more options, visit .

> **(attachments)**
>
> ![SelectInventoryScreenCapture.PNG](https://us1.discourse-cdn.com/ansible/original/2X/c/cbda3e26539a3f0f58082463d97bfacba71babfc.png)  
> ![InventoryScreenCapture.PNG](https://us1.discourse-cdn.com/ansible/original/2X/5/5b7152adfc677896ce12b15681833437d3625566.png)

---

<div class="post-metadata">

**Author:** ![Flavio\_Gobber](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@Flavio\_Gobber](https://forum.ansible.com/u/Flavio_Gobber)\
**Post date:** [June 4, 2019, 10:09am UTC](https://forum.ansible.com/t/how-configure-tower-template-to-use-dynamic-inventory-script/30404/7 "2019-06-04T10:09:39Z")

</div>

Hello Jonathan,

thank you for help, now I am able to use a Python script to create an inventory. Now I am not able to use a custom Python class inside the script. I have write a python class “class ScheduleInventory” into a file .py, this class receive in input two parameter. Then into Tower I have write this script:

#!/usr/bin/env python

from sched\_inv import ScheduleInventory  
ScheduleInventory(“schedwu.ini”,“Download & Install Update & Reboot - 2o gruppo”)

If I run this script it works well, but not in Tower, I think the origin is because the class is not in the right python lib folder, where i need to put the “class ScheduleInventory” into a file .py ?.

Thank you for help.

Best regards.

Flavio Gobber

en into the
