I’m interested in writing a simple tool which will serve as a building block for a test suite I’ll use to manage my inventory.
After perusing ansible-playbook,I grokked how to use the Inventory class and some of the factory functions it provides:https://gist.github.com/davidbirdsong/6722974
So what’s the best way to resolve and utilize vars plugins? I want to be expand all host and group variables exactly how ansible-playbook does.
I realize the truth is in the source, so I’m just hoping to get pointed in the right direction.
vars_plugins are not really a public facing feature, but are rather the system by which the “group_vars/” and “host_vars/” directories are internally implemented.
Right, and the contents of those directories have a direct affect on how a playbook will play out on a given host.
I was hoping to write a simple script to allow me to preview a hosts variables after all of the files affecting the state are referenced and inheritance and overriding is all worked out. Such a tool would help immensely as I figure out the model I want to use to cordon off various environments eg. staging vs production.
Is there something scary about how the plugins work internally that you’re trying to shield me from
Well, just that it wasn’t designed to be a pluggable interface with respect to those plugins so much. lookup plugins are different, they are something we talk about, versus, say, an internalsism.
Nothing especially scary, but they won’t help you preview what variables are going on.
What you may wish to do is just have the playbook dump host variables in a template.
https://coderwall.com/p/13lh6w
Though I should point out dumping hostvars like that won’t function anymore as it’s more of a virtual dictionary, you can do
{{ hostvars[‘inventory_hostname’] }}
in that template, however.