# Import of local module\_utils within local action\_plugin not working

**URL:** <https://forum.ansible.com/t/import-of-local-module-utils-within-local-action-plugin-not-working/43965>\
**Category:** Get Help\
**Tags:** module, plugin, collections\
**Created:** [July 21, 2025, 11:12am UTC](https://forum.ansible.com/t/import-of-local-module-utils-within-local-action-plugin-not-working/43965 "2025-07-21T11:12:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amartyasinha](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/amartyasinha/32/9093_2.png) [@amartyasinha](https://forum.ansible.com/u/amartyasinha)\
**Post date:** [July 21, 2025, 11:12am UTC](https://forum.ansible.com/t/import-of-local-module-utils-within-local-action-plugin-not-working/43965/1 "2025-07-21T11:12:48Z")

</div>

I had to use my custom collection in Zuul native playbook runs, but seems like it is not possible to install custom collection on zuul executor. So, I created a role similar to [this](https://opendev.org/zuul/zuul-jobs/src/branch/master/roles/upload-logs-base) to use my custom modules and action plugins in native Zuul playbooks.

The issue is, I’m able to import and use module\_utils in modules, but it is not working in case of action\_plugins.

Here is a sample role structure:

```auto
.
├── action_plugins
│ └── my_action1.py
├── library
│ └── my_module1.py
├── modules_utils
│ └── my_module_utils1.py
└── tasks
    └── main.yaml

```

When I call `my_module1` within task, it is able to resolve it’s dependency from `module_utils`, but the same is not true for `my_action1` action plugin. It fails with the following error:

```auto
ERROR! Unexpected Exception, this is probably a bug: No module named 'ansible.plugins.module_utils'

```

I’ve tried to import in two ways:

- first as `from ansible.module_utils.xyz import abc` [source](https://docs.ansible.com/ansible/latest/dev_guide/developing_module_utilities.html)
- second as `from ..module_utils.xyz import abc` [source](https://opendev.org/zuul/zuul-jobs/src/branch/master/roles/upload-logs-base/library/zuul_swift_upload.py#L58)  
Both ways gave errors with action plugins, while modules worked.

I even tried adding [this](https://www.reddit.com/r/ansible/comments/fm0tpw/import_python_utility_module_inside_a_roles/) but even it didn’t work for me.

I’ve tried running this directly on Ansible version 2.15.13 on my laptop as well through Zuul executor which was using Ansible Version: 2.15.12, and the result was same.

Any guidance to use local `module_utils` within local `action_plugins` within a role would be appreciated.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [July 21, 2025, 2:58pm UTC](https://forum.ansible.com/t/import-of-local-module-utils-within-local-action-plugin-not-working/43965/2 "2025-07-21T14:58:40Z")

</div>

This is a limitation of the “legacy” plugin system. The legacy system only allows for `module_utils` to be used by modules. In order to use `module_utils` in other plugin types, you would need to organize them within a collection.

> **[Developing collections — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/dev_guide/developing_collections.html)**

---

<div class="post-metadata">

**Author:** ![amartyasinha](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/amartyasinha/32/9093_2.png) [@amartyasinha](https://forum.ansible.com/u/amartyasinha)\
**Post date:** [July 21, 2025, 3:25pm UTC](https://forum.ansible.com/t/import-of-local-module-utils-within-local-action-plugin-not-working/43965/3 "2025-07-21T15:25:34Z")

</div>

Well, collections are not an option for me as it’s not possible to install custom collections on Zuul executor. Maybe I’ll have to deal with nested ansible playbook call.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [July 21, 2025, 3:51pm UTC](https://forum.ansible.com/t/import-of-local-module-utils-within-local-action-plugin-not-working/43965/4 "2025-07-21T15:51:10Z")

</div>

you can install collections adjacent to the play exactly the same as you are doing with your other plugins:

```auto
collections/ansible_collections/me/mycoll/plugins/ ...

```

---

<div class="post-metadata">

**Author:** ![amartyasinha](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/amartyasinha/32/9093_2.png) [@amartyasinha](https://forum.ansible.com/u/amartyasinha)\
**Post date:** [July 21, 2025, 5:33pm UTC](https://forum.ansible.com/t/import-of-local-module-utils-within-local-action-plugin-not-working/43965/5 "2025-07-21T17:33:13Z")

</div>

Only if I had looked into the docs properly, I would’ve gotten the answer. Thanks for the help. I should start reading docs properly.

> **[Installing collections — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections_guide/collections_installing.html#installing-collections-adjacent-to-playbooks)**

---

<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:** [August 20, 2025, 5:34pm UTC](https://forum.ansible.com/t/import-of-local-module-utils-within-local-action-plugin-not-working/43965/6 "2025-08-20T17:34:14Z")

</div>

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