I’m rewriting portions of the Ansible training I do, and I noticed that I pay little attention to the YAML inventory format. I start by teaching the so-called INI file format, and later do an overview over what dynamic inventory is and the data it must return, but the YAML file I basically just gloss over. (It being YAML is not the reason.)

twitter poll

The unrepresentative poll didn’t really surprise me, but I got a few responses I will partially quote here out of interest.

I didn’t expect this:

I migrated from INI to YAML; easier to read and parse.

I did expect responses like these:

INI file, because it was used in the Ansible book I learnt from. My server fleet rarely changes so dynamic would be of minimal use and I wasn’t aware you could use YAML for inventories.

I had to switch from ini to yaml recently (fiddling with vault) and my opinion is different. Ini file is light and simple

For simple projects the ini environment, but for most projects a custom dynamic which is written in python and and is hooked into different cmdb’ish things

Usually ini, but for @Hetzner_Online -cloud-related setups I use custom (Python) dynamic inventories, sometimes in combination with a static ini. For my private OpenStack cloud I’m doing fine with static ini inventories so far.

Postgres based cmdb with a wrapper script for ansible-playbook that lets us create selective inventory on the fly

I pointed the responder in the (I hope) right direction. The answer to the question is, of course, yes it’s possible, but it requires a bit of programming. (This ad inventory may be a start.)

I did not know there was a dynamic inventory option. Do you know if you can use Windows AD OU’s as the inventory?

This might interest others:

I turned to using yaml inventories, at least as a base setup. which might include dynamic things (and inventory plugins configs are also yaml now). I really like how you can define everything (hosts, groups and their variables) in one single format, all set in folders & files.

Dynamic with YAML doing mapping. Details here

Then there were a few responses from people using ready-made dynamic inventory scripts:


I very much like this train of thought:

In my current work infra: inventory directory with #yaml files based on major group. Previously: dynamic from the monitoring tool. I liked the idea that a host had to be declared in monitoring first to exist. @ansible was activating the monitoring but it had to be declared first.


Dynamic, what else? From Zabbix inventory.

The generator plugin

Nice that we also have FreeBSD users:

I’d like to have dynamic inventory where I point it to my list of FreeBSD hosts and it could just auto discover all iocage jails and categorize them based on local things (subsection of host name or local file or zfs properties), but I’ve yet to see this actually work.

And finally one person who’s jumped onto the new 2.4 inventory plugins:

It’s being slowly replaced by inventory plugins, I learned it the hard way when sending a PR for an old JSON based inventory script.