# shared code in ./module\_utills/\*.py\`

**URL:** <https://forum.ansible.com/t/shared-code-in-module-utills-py/38403>\
**Category:** Ansible Project\
**Created:** [September 5, 2023, 6:24pm UTC](https://forum.ansible.com/t/shared-code-in-module-utills-py/38403 "2023-09-05T18:24:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 5, 2023, 6:24pm UTC](https://forum.ansible.com/t/shared-code-in-module-utills-py/38403/1 "2023-09-05T18:24:47Z")

</div>

Does a local, project specific ./module\_utils directory only work for sharing code between Ansible modules, or can it host shared python code for other types of plugins?

I’m trying to share a bit of code between a test plugin and a related filter plugin. It’s not working, and I can’t tell if it’s because I’m doing something wrong vs. “it isn’t supposed to work” that way.

Full disclosure: I did get this working by putting the test and filter code into a local collection structure under ./collections/ansible\_collections/my/local/{test,filter}/foo.py, but there are “external factors” preventing me from adopting that solution just yet. Besides, I really want to understand how this could work either way.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 5, 2023, 6:27pm UTC](https://forum.ansible.com/t/shared-code-in-module-utills-py/38403/2 "2023-09-05T18:27:42Z")

</div>

It only works for modules(library) and module\_utils in the structure of a project local, adjacent directories.

To use them for other plugin types, you need to use a collection structure, but there is no reason it cannot just be local like you otherwise would with `library` and `module_utils` dir. Dunno what the “external factors” are.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 5, 2023, 6:53pm UTC](https://forum.ansible.com/t/shared-code-in-module-utills-py/38403/3 "2023-09-05T18:53:10Z")

</div>

“External factors” are tool chains that assume everything under ./collections except for ./collections/requirements.yml are not local to the project. These need to be made smarter, incorporating `git ls-files` and friends for that determination.

If it really is a no-go — which seems to be what you’re saying — then I can quit digging this hole and put the effort into upgrading/fixing borken local tools. That needs to happen anyway, and apparently sooner rather than later. Thanks.
