# Where to put shared code of modules

**URL:** <https://forum.ansible.com/t/where-to-put-shared-code-of-modules/17704>\
**Category:** Ansible Developer\
**Created:** [March 9, 2015, 8:14pm UTC](https://forum.ansible.com/t/where-to-put-shared-code-of-modules/17704 "2015-03-09T20:14:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rene\_Moser](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Rene\_Moser](https://forum.ansible.com/u/Rene_Moser)\
**Post date:** [March 9, 2015, 8:14pm UTC](https://forum.ansible.com/t/where-to-put-shared-code-of-modules/17704/1 "2015-03-09T20:14:33Z")

</div>

Hi

I am developing modules for cloudstack [https://github.com/resmo/ansible-cloudstack](https://github.com/resmo/ansible-cloudstack) and having a bunch of modules which have some similar common code. I would like to separate this code into a separate file which can be imported (DRY).

Where can I put this code? Would be [https://github.com/ansible/ansible/tree/devel/lib/ansible/module\_utils](https://github.com/ansible/ansible/tree/devel/lib/ansible/module_utils) the right place?

I expect the modules go into modules-extra repo, does it matter?

Thanks for clarification.

Yours  
René

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 9, 2015, 8:15pm UTC](https://forum.ansible.com/t/where-to-put-shared-code-of-modules/17704/2 "2015-03-09T20:15:45Z")

</div>

Yes, module\_utils is the correct place for shared module code, it does  
not matter in which repo the module resides.  
You can check the openstack and amazon modules that already have  
shared code there.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 9, 2015, 9:24pm UTC](https://forum.ansible.com/t/where-to-put-shared-code-of-modules/17704/3 "2015-03-09T21:24:50Z")

</div>

​Wouldn't it make sense to have that share code within the modules  
repository? Basically making module\_utils also pluggeable perhaps?  
​

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 9, 2015, 9:36pm UTC](https://forum.ansible.com/t/where-to-put-shared-code-of-modules/17704/4 "2015-03-09T21:36:57Z")

</div>

We have had discussions on this, even moving all plugins to the  
core/extras repos, not just library modules. But most of this will  
have to wait until 1.9 is out and v2 is the main devel.

I'm remiss to open a topic in ansibl-devel about it until we have  
actual time to do something about it.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 9, 2015, 9:43pm UTC](https://forum.ansible.com/t/where-to-put-shared-code-of-modules/17704/5 "2015-03-09T21:43:04Z")

</div>

​That's perfect!​
