Accessing Ansible inventory externally

Hi all,
I’ve got a homegrown app where I’d love to be able to use Ansible’s inventory… I could of course use an external inventory for both, but Ansible’s built-in way of doing inventory and vars is really all I need so it would be great if there’s some way to get Ansible to dump that inventory for extrenal consumption.

One way of doing this that occurred to me was creating an external inventory script that really just queries Ansible (then my other app could just call “./hosts --list” or “./hosts --host foo” for what it needs). I haven’t looked into that too much yet, though, in case there was some easier way to do this that I’m missing.

I figure Ansible commander will also make this trivial, but i’m wondering if there’s a way to do it now :slight_smile:

thanks!
matt

Commander will allow access to inventory as a REST API.

(Injection and support for inventory scripts is not /quite/ there yet)

the basic inventory seem to be:

import ansible.inventory

inv = ansible.inventory.Inventory()

for group in inv.get_groups():
    print group.name
    for host in group.get_hosts():
        print ' ' + host.name

-sv

Awesome, thanks for the pointer Seth, this should get me what I need while I wait for commander :slight_smile:

matt