What is a proper way to use module_utils in action plugins

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.

Better create a collection, there it works flawlessly.

I think we had other discussions about it here, you might be able to find them with the search functionality.

1 Like

good idea! it appears that ansible-dev-tools project automate quite a lot for local ansible development.

I was able to install a collection in an editable mode that shares collection’s filesystem between a playbook and its original location. So changes in the collection are immediately visible in the playbook.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.