# dynamic inventory from .ssh/config

**URL:** <https://forum.ansible.com/t/dynamic-inventory-from-ssh-config/14562>\
**Category:** Ansible Project\
**Created:** [February 13, 2014, 11:37am UTC](https://forum.ansible.com/t/dynamic-inventory-from-ssh-config/14562 "2014-02-13T11:37:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Karasek1](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@Tomas\_Karasek1](https://forum.ansible.com/u/Tomas_Karasek1)\
**Post date:** [February 13, 2014, 11:37am UTC](https://forum.ansible.com/t/dynamic-inventory-from-ssh-config/14562/1 "2014-02-13T11:37:09Z")

</div>

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](http://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](https://github.com/t0mk/various/blob/master/ssh_config-inventory.py)

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

Cheers,  
Tomas

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 13, 2014, 2:06pm UTC](https://forum.ansible.com/t/dynamic-inventory-from-ssh-config/14562/2 "2014-02-13T14:06:20Z")

</div>

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’"

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 13, 2014, 2:09pm UTC](https://forum.ansible.com/t/dynamic-inventory-from-ssh-config/14562/3 "2014-02-13T14:09:51Z")

</div>

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

[https://github.com/ansible/ansible/tree/devel/plugins/inventory](https://github.com/ansible/ansible/tree/devel/plugins/inventory)

---

<div class="post-metadata">

**Author:** ![Tomas\_Karasek1](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@Tomas\_Karasek1](https://forum.ansible.com/u/Tomas_Karasek1)\
**Post date:** [February 13, 2014, 2:39pm UTC](https://forum.ansible.com/t/dynamic-inventory-from-ssh-config/14562/4 "2014-02-13T14:39:34Z")

</div>

Cool. I cleaned it a bit and created:  
[https://github.com/ansible/ansible/pull/5995](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/?
