Our inventory comes from multiple sources, a couple dynamic and one
static. Ansible itself can pull them all together into a unified
inventory, but we'd like to transform the dynamic sources on the way in,
without having to hack the scripts that produce them, so we can use the
stock versions from .../plugins/inventory. For example, we might want to
set some variables based on what groups a host is in, add it to some
additional groups (e.g. if a host is in 'prod' and 'webserver', also add
it to 'prod-webservers'), etc.

I started out by writing a Python script which would take the output of
those scripts, json.loads() it into a big data structure, and then create
a new data structure that I could json.dumps() for Ansible to consume. 
Along the way I ran into 'import ansible.inventory', which seemed like it
might be more appealing (and more Pythonic): Rather than slogging through
these giant data structures, perhaps I'd like to create an empty
ansible.inventory.Inventory object, and populate it with the information
from the dynamic and static sources.

I had two questions about that:

(1) Does this seem like a reasonable approach?

(2) If so, is there an easy way to dump the contents of an
    ansible.inventory.Inventory object into the JSON that Ansible itself
    wants to consume? I didn't see an obvious method for that, but might
    have missed something.

Thanks in advance for any advice and input.

                                      -Josh ([email protected])



This email is intended for the person(s) to whom it is addressed and may 
contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, 
distribution, copying, or disclosure by any person other than the addressee(s) 
is strictly prohibited. If you have received this email in error, please notify 
the sender immediately by return email and delete the message and any 
attachments from your system.

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/21458.25083.499226.766078%40care.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to