Dynamic inventory script from Git project

822 views
Skip to first unread message

Piotr Wojciechowski

unread,
May 27, 2018, 3:49:51 PM5/27/18
to AWX 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

Kosala Atapattu

unread,
May 27, 2018, 5:50:32 PM5/27/18
to Piotr Wojciechowski, AWX Project
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

Kosala



--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project+unsubscribe@googlegroups.com.
To post to this group, send email to awx-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/d7c30ab9-b433-4161-86ce-eae22e0c111a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alan Rominger

unread,
May 29, 2018, 8:48:10 AM5/29/18
to Kosala Atapattu, Piotr Wojciechowski, AWX Project
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.

Alan
github: AlanCoding

Kosala Atapattu

unread,
May 29, 2018, 3:00:06 PM5/29/18
to Alan Rominger, Piotr Wojciechowski, AWX Project
Hi Alan,

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

Kosala


Piotr Wojciechowski

unread,
May 29, 2018, 3:55:32 PM5/29/18
to Alan Rominger, Kosala Atapattu, AWX 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 :)


Pozdrawiam,

-- 
Piotr Wojciechowski  (CCIE #25543)  | "The trouble with being a god is
    Network Solutions Architect     | that you've got no one to pray to"
   https://blog.it-playground.eu    |   — (Terry Pratchett, Small Gods)




doppalapudi saikumar

unread,
May 29, 2018, 3:57:26 PM5/29/18
to Piotr Wojciechowski, AWX Project
Hi,

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

--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages