Import of local module_utils within local action_plugin not working

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 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:

.
├── 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:

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
  • second as from ..module_utils.xyz import abc source
    Both ways gave errors with action plugins, while modules worked.

I even tried adding this 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.

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.

1 Like

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.

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

collections/ansible_collections/me/mycoll/plugins/ ...
1 Like

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.