Hi Justin,
I hate to revive old threads, but this one is directly relevant to me.
My inventory system is key/value-based, rather than Ansible's group-based. It's also huge and can't be cleanly separated into sub-sets (I could make some generalisations, but there'd always be exceptions).
The approach that I've used so far has been to use wrapper-scripts to ansible and ansible-playbook which set some environment variables, and then call ansible* with my inventory script. The inventory script parses the playbook to evaluate the host patterns and then only includes relevant hosts.
https://github.com/ansible/ansible/issues/7622 (Closed, Not Implemented) explains my approach.
Using environment variables and wrapper scripts does seem very hacky to me (although it works fine), but I'm hoping for an alternative solution at some point.
In the ideal world, we'd be able to write our own internal inventory plugin for Ansible, instead of using a script. It would then be the inventory plugins's responsibility to produce a stable inventory based on all the available information.
I think one of the concerns from the core team is that alternative internally pluggable inventories wouldn't be stable, which could cause issues with logging, group membership changing halfway through a playbook, etc.
I don't see that as a good reason to not support an internally pluggable inventory, but it'd be a good reason to make the internal API's requirements extremely clear. A well defined internal-inventory API and a clean default implementation would also be its own reward.
Given that I have something working and limited personal time these days, I'm unable to attack this myself. I'd certainly get involved if the core team picked this up, however.
Best Regards,
Robert Thomson