# What is a proper way to use module\_utils in action plugins

**URL:** <https://forum.ansible.com/t/what-is-a-proper-way-to-use-module-utils-in-action-plugins/11011>\
**Category:** Get Help\
**Created:** [November 20, 2024, 5:39am UTC](https://forum.ansible.com/t/what-is-a-proper-way-to-use-module-utils-in-action-plugins/11011 "2024-11-20T05:39:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mykhailo\_Nesterenko](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mykhailo_nesterenko/32/5269_2.png) [@Mykhailo\_Nesterenko](https://forum.ansible.com/u/Mykhailo_Nesterenko)\
**Post date:** [November 20, 2024, 5:39am UTC](https://forum.ansible.com/t/what-is-a-proper-way-to-use-module-utils-in-action-plugins/11011/1 "2024-11-20T05:39:14Z")

</div>

I am sharing some code between module and its action plugin in a module\_utils module.

module\_utils is placed adjacent to its playbook:

```auto
.
├── 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.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [November 20, 2024, 5:53am UTC](https://forum.ansible.com/t/what-is-a-proper-way-to-use-module-utils-in-action-plugins/11011/2 "2024-11-20T05:53:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mykhailo\_Nesterenko](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mykhailo_nesterenko/32/5269_2.png) [@Mykhailo\_Nesterenko](https://forum.ansible.com/u/Mykhailo_Nesterenko)\
**Post date:** [November 24, 2024, 10:24am UTC](https://forum.ansible.com/t/what-is-a-proper-way-to-use-module-utils-in-action-plugins/11011/3 "2024-11-24T10:24:00Z")

</div>

good idea! it appears that ansible-dev-tools [project](https://ansible.readthedocs.io/projects/dev-tools/) 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.

---

<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:** [December 24, 2024, 10:24am UTC](https://forum.ansible.com/t/what-is-a-proper-way-to-use-module-utils-in-action-plugins/11011/4 "2024-12-24T10:24:45Z")

</div>

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