I am sharing some code between module and its action plugin in a module_utils module.
module_utils is placed adjacent to its playbook:
.
├── module_utils/
│ └── shared_util.py
├── library/
│ └── module.py
├── action_plugins/
│ └── module.py
└── playbook.yml
library/module.py
can successfully import in runtime from ansible.module_utils.shared_util
However action_plugins/module.py
does not see the package ansible.module_utils.shared_util
.
So far in action plugin I just import module_utils.shared_util
and start ansible-playbook
with PYTHONPATH
set to the directory where playbook.yml
is stored.
This approach looks hacky and I hope there is more streamlined way to import module util.