ansible roles and custom module structure

Skip to first unread message

Living Neutral

Feb 15, 2023, 12:04:04 AM2/15/23
to Ansible Development
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. 


My import statements
from Python_Collections import helper_package.helper_module

Brian Coca

Feb 21, 2023, 11:37:54 AM2/21/23
to Living Neutral, Ansible Development
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/.

Brian Coca

Brian Coca

Feb 21, 2023, 11:38:55 AM2/21/23
to Living Neutral, Ansible Development
Reply all
Reply to author
0 new messages