Dynamic Groups In Custom Dynamic Inventory

I have a custom dynamic inventory whose source data is basically a custom flat-file database that consists of a hostname and a bunch of key=value pairs. In the dynamic inventory, I’m using those key=value pairs as hostvars. I currently do not have any defined groups.

What I would like to do is create groups on the fly using the hostvars. e.g. If I want to run a playbook against all of the hosts in the dynamic inventory with key=value pair of production=false, then run that same playbook against all those with production=true, then run it against production=true and platform=linux, etc.

I don’t think I should have to create a separate playbook for all of those, maybe I do. I would think there is a way to do that via command-line arguments or somesuch. I just can’t find any straightforward documentation concerning that.

Thanks

This might be what you want.

http://docs.ansible.com/ansible/devel/plugins/inventory/constructed.html

This looks like the right idea…Just need to figure out how to get it working.