# Module lookup

**URL:** <https://forum.ansible.com/t/module-lookup/11558>\
**Category:** Ansible Project\
**Created:** [May 18, 2012, 4:09pm UTC](https://forum.ansible.com/t/module-lookup/11558 "2012-05-18T16:09:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Goodall](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Matt\_Goodall](https://forum.ansible.com/u/Matt_Goodall)\
**Post date:** [May 18, 2012, 4:09pm UTC](https://forum.ansible.com/t/module-lookup/11558/1 "2012-05-18T16:09:08Z")

</div>

Hi,

I wrote a simple module this afternoon and then discovered that it  
really needs to be copied to the single, shared Ansible module  
directory to be found by a playbook.

I would like to extend the module lookup to search multiple directories, to:

- provide a way for other modules, e.g. the proposed contrib library,  
to be added  
- allow project-specific modules

I found the relevant code and it was a simple change to make it search  
through a list of paths instead, allowing:

&nbsp;&nbsp;&nbsp;&nbsp;ansible -M /usr/share/ansible:/path/to/another/library

Commit is here,  
[https://github.com/emgee/ansible/commit/3a447f8b3295c23589bfe5a5a010eb9bf6b6925a](https://github.com/emgee/ansible/commit/3a447f8b3295c23589bfe5a5a010eb9bf6b6925a).

Assuming it's a change you agree with I think it's useful enough like  
that. However, it would probably be nicer to be able to \*extend\* the  
module search path to avoid knowing where Ansible's library is  
installed.

There are probably a couple of options that would work here:

&nbsp;&nbsp;&nbsp;&nbsp;--module-path  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;as for my commit  
&nbsp;&nbsp;&nbsp;&nbsp;--extend-module-path  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;append path(s) to above module path

&nbsp;&nbsp;&nbsp;&nbsp;Should be a safe change.

OR

&nbsp;&nbsp;&nbsp;&nbsp;--module-path  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;append path(s), could even be callable multiple times  
&nbsp;&nbsp;&nbsp;&nbsp;--no-default-modules  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;don't include Ansible's library

&nbsp;&nbsp;&nbsp;&nbsp;Changes behaviour for anyone relying on current --module-path behaviour.

Firstly is this a good change to make? Secondly, would you prefer one  
of the above command line changes (or something completely different)  
before it's merged?

Thanks, Matt

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 18, 2012, 4:56pm UTC](https://forum.ansible.com/t/module-lookup/11558/2 "2012-05-18T16:56:58Z")

</div>

> Commit is here,  
> [https://github.com/emgee/ansible/commit/3a447f8b3295c23589bfe5a5a010eb9bf6b6925a](https://github.com/emgee/ansible/commit/3a447f8b3295c23589bfe5a5a010eb9bf6b6925a).

This seems reasonable, send me a pull request and we can include in 0.5

> Assuming it’s a change you agree with I think it’s useful enough like  
> that. However, it would probably be nicer to be able to _extend_ the  
> module search path to avoid knowing where Ansible’s library is  
> installed.
> 
> There are probably a couple of options that would work here:
> 
> –module-path  
> as for my commit  
> –extend-module-path  
> append path(s) to above module path

Using the existing option like you have now is best, where if you want to specify a module path  
you just have to include the stock one too.

Keep it simple and explicit…

---

<div class="post-metadata">

**Author:** ![Matt\_Goodall](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Matt\_Goodall](https://forum.ansible.com/u/Matt_Goodall)\
**Post date:** [May 18, 2012, 8:10pm UTC](https://forum.ansible.com/t/module-lookup/11558/3 "2012-05-18T20:10:19Z")

</div>

> Commit is here,  
> [https://github.com/emgee/ansible/commit/3a447f8b3295c23589bfe5a5a010eb9bf6b6925a](https://github.com/emgee/ansible/commit/3a447f8b3295c23589bfe5a5a010eb9bf6b6925a).
> 
> This seems reasonable, send me a pull request and we can include in 0.5

Done.

> Assuming it's a change you agree with I think it's useful enough like  
> that. However, it would probably be nicer to be able to \*extend\* the  
> module search path to avoid knowing where Ansible's library is  
> installed.
> 
> There are probably a couple of options that would work here:
> 
> --module-path  
> as for my commit  
> --extend-module-path  
> append path(s) to above module path
> 
> Using the existing option like you have now is best, where if you want to  
> specify a module path  
> you just have to include the stock one too.
> 
> Keep it simple and explicit...

Yep fair enough, and that's the reason why I did the obvious (and  
easy) bit first and left the other bit for discussion.

- Matt
