I wonder what would be a good solution to manage an environment with a combination of dynamic and static hosts and vars and groups.
I'm thinking of a combination of physical hosts in a datacenter with a combination of specific tasks (physical database node) plus Proxmox Hosts managing some dynamic VMs, together with some cloud providers for managing new VMs in some situation, where the physical performance is not enough (outsource performance peeks).
In that case - a dynamic inventory is a good practice. Of course there are some plugins for AWS, Hetzner, etc. But is it possible to combine that together with static entries?
I build a database with all the entries and scripts that updates the list of cloud VMs per request in the database. All the dynamic hosts together with the static hosts and some group vars, host vars are stored in the database. And there is a webservice that outputs the JSON dynamic inventory that a python script loads and that is used as a dynamic inventory in my playbooks.
My question is - am I the only one with this kind of setup? When I think of a company with some VMWare hosts together with dynamic number of VMs on that hosts plus some other physical systems it would be "clear" that there should be some kind of "tool" or help for this setup. But as far as I can see, there is either a static inventory (YAML, INI) or a dynamic inventory (JSON). But does every admin develops their own dynamic inventory database? Or is there a given software "product" or "project"? Or is it a "better" practice to have different inventories for "static" and "dynamic" environments?
Ansible has several released inventory plugins. Yes, you can combine them, either as multiple
-i
options, or specify a directory containing multiple inventories.For example, you might have all of these in
inventory/stage/
andinventory/prod/
directories:Group names should be consistent for a given thing, so plays can use static patterns.
Constructed is pretty neat. Use Jinja expressions on facts from inventory or hosts to create groups and vars. For example, you might want some ec2 tag, plus some hostname regex, to be members of a group.
Should this not be sufficient, you may write your own inventory plugins. Usually, these talk to one API, say if you hack on a Proxmox inventory plugin. Or, abandon the multiple inventory on the Ansible side, find a multi cloud tool that works for you, and make that emit JSON for inventory.