# Dynamic inventory script from Git project

**URL:** <https://forum.ansible.com/t/dynamic-inventory-script-from-git-project/27646>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [May 27, 2018, 7:49pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-from-git-project/27646 "2018-05-27T19:49:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piotr\_Wojciechowski](https://avatars.discourse-cdn.com/v4/letter/p/9de0a6/32.png) [@Piotr\_Wojciechowski](https://forum.ansible.com/u/Piotr_Wojciechowski)\
**Post date:** [May 27, 2018, 7:49pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-from-git-project/27646/1 "2018-05-27T19:49:51Z")

</div>

Hi everyone,

Correct me if I’m wrong - it is not possible to use dynamic inventory script directly from the project? If I want to use inventory from the project, which is pulled from Git, this has to be the static inventory file. The only way to use the script is adding it manually to AWX and then use as inventory source?

What I would like to achieve is that every time I pull the project from the repository I want the script itself to update as well

Regards,  
Piotr

---

<div class="post-metadata">

**Author:** ![Kosala\_Atapattu1](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kosala\_Atapattu1](https://forum.ansible.com/u/Kosala_Atapattu1)\
**Post date:** [May 27, 2018, 9:50pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-from-git-project/27646/2 "2018-05-27T21:50:10Z")

</div>

Hi Piotr,

AFAIK, you can’t fetch an inventory script dynamically from a git. However, it might be possible to generate the same inventory from the script after pulling it down from a repo. Have a look at this [https://www.ansible.com/inventory-essentials-with-ansible-tower](https://www.ansible.com/inventory-essentials-with-ansible-tower). You can find few good options to do this dynamically. I’ve not tried this yet, but this opens up many possibilities.

Cheers,  
Ko

---

<div class="post-metadata">

**Author:** ![AlanCoding](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alancoding/32/301_2.png) [@AlanCoding](https://forum.ansible.com/u/AlanCoding)\
**Post date:** [May 29, 2018, 12:48pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-from-git-project/27646/3 "2018-05-29T12:48:07Z")

</div>

You can use dynamic inventory scripts from source control. From what you wrote, it sounds like you’re doing it the right way. What particular thing did you get hung up on?

There are some nuances to getting your script so that it can be used by Ansible generally. The CLI ansible-inventory is a tool designed for testing these things. You need to run `chmod +x` on your file to make it executable, and it also needs to begin with “#!/usr/bin/env python”, because Ansible does not assume that your script is a python script.

> What I would like to achieve is that every time I pull the project from the repository I want the script itself to update as well

It sounds the “update on project change” feature of SCM-based inventory sources. There’s a box you click to have it auto-update when the project pulls a new revision. This won’t run for every update, only when the project revision changes, because it was intended primarily for use with static inventory content.

---

<div class="post-metadata">

**Author:** ![Kosala\_Atapattu1](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kosala\_Atapattu1](https://forum.ansible.com/u/Kosala_Atapattu1)\
**Post date:** [May 29, 2018, 6:59pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-from-git-project/27646/4 "2018-05-29T18:59:43Z")

</div>

Hi Alan,

Do you have any instructions as to how to build an inventory from a script in a project?

---

<div class="post-metadata">

**Author:** ![Piotr\_Wojciechowski](https://avatars.discourse-cdn.com/v4/letter/p/9de0a6/32.png) [@Piotr\_Wojciechowski](https://forum.ansible.com/u/Piotr_Wojciechowski)\
**Post date:** [May 29, 2018, 7:55pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-from-git-project/27646/5 "2018-05-29T19:55:29Z")

</div>

Hi Alan,

Thank you for your answer. I was not aware of those two requirements. I tested this feature few weeks ago, its was AWX 1.0.5 back then and ansible 2.5.0, right now latest container is 1.0.6.11 and ansible 2.5.3.

Now I have different script in the project. Both current and previous one has the “#!/usr/bin/env python” at the beginning, I am not sure about the +x. Current script have it sent and is visible, can’t verify the previous one.

I tested it and inventory script have to have +x set when it is pushed to repository so when you pull it on awx it is pulled with +x set. Then the script is visible on ‘inventory file’ pull down list in the source configuration. Changing the executable flag when project is already pulled will not solve the problem.

Thanks again for clarification on this case 🙂

Pozdrawiam,

---

<div class="post-metadata">

**Author:** ![doppalapudi\_saikumar](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@doppalapudi\_saikumar](https://forum.ansible.com/u/doppalapudi_saikumar)\
**Post date:** [May 29, 2018, 7:57pm UTC](https://forum.ansible.com/t/dynamic-inventory-script-from-git-project/27646/6 "2018-05-29T19:57:15Z")

</div>

Hi,

Do you know any custom script that can pull inventory from terraform to Ansible inveratory (dynamic).
