mitogen icon indicating copy to clipboard operation
mitogen copied to clipboard

Action plugin fetch fails when used inside a reimported role from a collection

Open gboutry opened this issue 2 years ago • 0 comments

  • Which version of Ansible are you running?

    • 2.9.27 - mitogen 0.2.10
    • 2.10.17 - mitogen 0.3.3
  • Is your version of Ansible patched in any way? No

  • Are you running with any custom modules, or module_utils loaded? No

  • Have you tried the latest master version from Git? No

  • Do you have some idea of what the underlying problem may be? Yes, the

  • Mention your host and target OS and versions

    • My host: Fedora 36
    • Target: Centos 7
  • Mention your host and target Python versions

    • My Host: python3.6 when ansible 2.9, python3.10 when 2.10
    • Target: python2.7
  • If reporting a crash or hang in Ansible, please rerun with -vvv and include 200 lines of output around the point of the error, along with a full copy of any traceback or error text in the log. Beware "-vvv" may include secret data! Edit as necessary before posting. The only important logs when running with verbose mode:

TASK [tosit.tdp_prerequisites.certificates : Fetch certificate authority's certificate] ******************************************************************************************************************************************************
fatal: [gboutry-master-01]: FAILED! => {}

MSG:

the handler 'fetch' was not found
  • If reporting any kind of problem with Ansible, please include the Ansible version along with output of "ansible-config dump --only-changed".

Possible solution

I found the root cause of the issue, it's because of ansible action plugin resolution when collections are involved that will create a candidate list with the name of plugin prepended with collections given in the argument collection_list.

This fails because the plugin mitogen_fetch is not from a collection. (fetch is renamed mitogen fetch).

The following solution works for me in 0.2.9 and 0.3.3:

diff --git a/ansible_mitogen/strategy.py b/ansible_mitogen/strategy.py
index 0a98e316..257a4e31 100644
--- a/ansible_mitogen/strategy.py
+++ b/ansible_mitogen/strategy.py
@@ -88,7 +88,9 @@ def wrap_action_loader__get(name, *args, **kwargs):
     get_kwargs = {'class_only': True}
     if name in ('fetch',):
         name = 'mitogen_' + name
-    get_kwargs['collection_list'] = kwargs.pop('collection_list', None)
+        get_kwargs['collection_list'] = None
+    else:
+        get_kwargs['collection_list'] = kwargs.pop('collection_list', None)
 
     klass = ansible_mitogen.loaders.action_loader__get(name, **get_kwargs)
     if klass:

I'm ready to propose a pull request with the solution if you find the solution to be correct.

gboutry avatar Nov 03 '22 11:11 gboutry