# ansible roles and custom module structure

**URL:** <https://forum.ansible.com/t/ansible-roles-and-custom-module-structure/37661>\
**Category:** Ansible Developer\
**Created:** [February 15, 2023, 5:04am UTC](https://forum.ansible.com/t/ansible-roles-and-custom-module-structure/37661 "2023-02-15T05:04:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Living\_Neutral](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@Living\_Neutral](https://forum.ansible.com/u/Living_Neutral)\
**Post date:** [February 15, 2023, 5:04am UTC](https://forum.ansible.com/t/ansible-roles-and-custom-module-structure/37661/1 "2023-02-15T05:04:04Z")

</div>

Hello Team,

I have a question about how proper ansible roles and modules should work.

I’m currently working on an ansible role where it has a custom module in it to do some api calls. However with the way the module is set up there is the base module which calls some code not directly present in the module file. I’ll have a folder structure at the bottom for clarification. The reason I ask is that I’m running into issues running this code in tower. As it works locally however fails due to ansible tower not being able to find the correct imports for the file. Is this just a limitation of ansible? Or is there something wrong with how I’m configuring the project thus leading it to not be able to detect the extra helper files? This is in python by the way to avoid confusion. I’ll clarify anything unclear in the replies.

role/  
library/  
base\_module.py  
Python\_Collections/  
helper\_package/  
helper\_module.py

My import statements  
base\_module.py

---

<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:** [February 21, 2023, 4:35pm UTC](https://forum.ansible.com/t/ansible-roles-and-custom-module-structure/37661/2 "2023-02-21T16:35:48Z")

</div>

That won't work as modules can only rely on code in themselves and  
module\_utils, this is because they are designed for remote execution  
so Ansible creates a 'package' to deliver on the remote host and  
execute. It is not feasable to follow any/all imports of code as you  
can end up with something unusable, hence the limitation to only  
depend on code in module\_utils/.  
[https://docs.ansible.com/ansible/latest/reference\_appendices/module\_utils.html](https://docs.ansible.com/ansible/latest/reference_appendices/module_utils.html)

---

<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:** [February 21, 2023, 4:36pm UTC](https://forum.ansible.com/t/ansible-roles-and-custom-module-structure/37661/3 "2023-02-21T16:36:51Z")

</div>

sorry, wrong link before  
[https://docs.ansible.com/ansible/latest/dev\_guide/developing\_module\_utilities.html](https://docs.ansible.com/ansible/latest/dev_guide/developing_module_utilities.html)
