dynamic inventory from .ssh/config

Hello,

at first, thanks for all the good work on Ansible, I like the project a lot! I spent more than a year working with Puppet, and I have to say that using Ansible is much less headache.

I tend to work with nodes of various nature. Some inventory info I can get from remote service (OpenStack Nova) and some I need to hardcode (“pet” nodes). I really like that the “hostfile” config option can take a directory as an agument, and evaluates everything below!

For the static part of my infrastructure, I use .ssh/config. I still didn’t get used to the Ansible “ini” static inventory. I wrote an inventory script which parses the .ssh/config and lets you use the Host alias with ansible. For example, if you have .ssh/config containing:

Host git
HostName git.domain.org
User tkarasek
IdentityFile /home/tomk/keys/thekey

You can do $ ansible git -m ping.

The script is at
https://github.com/t0mk/various/blob/master/ssh_config-inventory.py

Should I create pull request? Or is it against ansible philosophy?

Cheers,
Tomas

I’d be fine to include something like this in examples for those that want to use it.

Pull request would need a few things:

So the DOCUMENTATION string in here makes it look like it’s a module, but it’s really an inventory script, so I’d remove the “DOCUMENTATION” YAML block, since that was a bit confusing to me.

There are a few comments that don’t make sense, such as

" help_check_doc = ‘Check that DOCUMENTATION is valid yaml’"

Once you’ve got it tweaked, it can live here:

https://github.com/ansible/ansible/tree/devel/plugins/inventory

Cool. I cleaned it a bit and created:
https://github.com/ansible/ansible/pull/5995

Is there any guide on how to write unit tests for things like inventory plugins? Shall I just drop a unit test in tests/?