# Testing inventory plugins

**URL:** <https://forum.ansible.com/t/testing-inventory-plugins/29580>\
**Category:** Ansible Developer\
**Created:** [January 31, 2019, 3:00pm UTC](https://forum.ansible.com/t/testing-inventory-plugins/29580 "2019-01-31T15:00:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_R](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@Josh\_R](https://forum.ansible.com/u/Josh_R)\
**Post date:** [January 31, 2019, 3:00pm UTC](https://forum.ansible.com/t/testing-inventory-plugins/29580/1 "2019-01-31T15:00:31Z")

</div>

I’m writing an inventory plugin that gets a list of online machines from an active directory OU structure and dynamically creates groups and host details from it.

However, as I write it - I’d like to be able to test the incremental changes by just calling parser() directly.

Does anyone have an example call to parser() to test plugins? For example - my definition is :

def parse(self, inventory, loader, path, cache=True):

I temporarily removed all the required variables in order to call it, but I’m now at a point I need to test the inventory calls.

Also. any guidance on testing of plugins would be appreciated.

Thanks,

Josh

---

<div class="post-metadata">

**Author:** ![Alb0t](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@Alb0t](https://forum.ansible.com/u/Alb0t)\
**Post date:** [February 1, 2019, 2:19am UTC](https://forum.ansible.com/t/testing-inventory-plugins/29580/2 "2019-02-01T02:19:30Z")

</div>

I found the inventory script documentation (on how to create your own) to be severely lacking… ☹ i eventually gave up on trying it.  
I hope you find an answer, but I just wanted to vent my frustration with the docs here haha

---

<div class="post-metadata">

**Author:** ![acozine1](https://avatars.discourse-cdn.com/v4/letter/a/c89c15/32.png) [@acozine1](https://forum.ansible.com/u/acozine1)\
**Post date:** [February 1, 2019, 3:46pm UTC](https://forum.ansible.com/t/testing-inventory-plugins/29580/3 "2019-02-01T15:46:01Z")

</div>

Thanks Albert for your feedback on the documentation - I’m sorry it hasn’t helped you achieve your goals. Do you remember where you got stuck? If so, would you be willing to share the details so we can improve the docs?

We’ve made quite a few changes recently to the main page about writing inventory plugins ([https://docs.ansible.com/ansible/devel/dev\_guide/developing\_inventory.html#developing-inventory](https://docs.ansible.com/ansible/devel/dev_guide/developing_inventory.html#developing-inventory)) and would welcome input in making it even more detailed and helpful.

Josh, if you solve your challenges, I encourage you to contribute what you learn back to the documentation so everyone can benefit from your exploration.

Feel free to respond via email or join the #ansible-docs IRC channel on Freenode IRC.

Thanks,  
Alicia

Alicia Cozine  
Lead Technical Writer, Ansible by Red Hat

---

<div class="post-metadata">

**Author:** ![Josh\_R](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@Josh\_R](https://forum.ansible.com/u/Josh_R)\
**Post date:** [February 4, 2019, 3:03pm UTC](https://forum.ansible.com/t/testing-inventory-plugins/29580/4 "2019-02-04T15:03:43Z")

</div>

Hi Alicia,

The part that seems to be lacking for me is testing of inventory plugins (or plugins in general). My current assumption is I’ll need to setup the ansible development environment and create a unit test.

Can you confirm if that is the case? Scripts were significantly easier, as I could just visually inspect the --list output of the script to confirm the json output etc. I cant seem to find a way to correctly call the inventory plugin to test all of its results. Specifically, most of the unit tests don’t actually test calls to the inventory class. Such as inventory.add\_host() etc.

Thanks,

Josh

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 11, 2019, 10:48pm UTC](https://forum.ansible.com/t/testing-inventory-plugins/29580/5 "2019-03-11T22:48:48Z")

</div>

Also there is a bug with 'adjacent' directories for inventory plugins,  
this should fix it [https://github.com/ansible/ansible/pull/51177](https://github.com/ansible/ansible/pull/51177)
