Dynamic inventory script from Git project

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

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. You can find few good options to do this dynamically. I’ve not tried this yet, but this opens up many possibilities.

Cheers,
Ko

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.

Hi Alan,

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

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 :slight_smile:

Pozdrawiam,

Hi,

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