mitogen icon indicating copy to clipboard operation
mitogen copied to clipboard

httpapi connection support

Open dvwh opened this issue 1 year ago • 2 comments

Currently, Mitogen supports several connection types like local, ssh, docker and more. However, it lacks support for httpapi.

Is it possible to reuse, adapt the existing connection plugins so httpapi can be used in Ansible plays with mitogen, or mitogen needs separate implementation of a connection plugin specifically for httpapi?

dvwh avatar Jul 04 '24 10:07 dvwh

Workaround that seems to work:

diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py
index 6bdf11ba..d266b394 100644
--- a/ansible_mitogen/connection.py
+++ b/ansible_mitogen/connection.py
@@ -41,6 +41,7 @@ import time
 import ansible.constants as C
 import ansible.errors
 import ansible.plugins.connection
+from ansible.plugins.action.normal import ActionModule
 
 import mitogen.core
 
@@ -585,7 +586,7 @@ class Connection(ansible.plugins.connection.ConnectionBase):
             if f.f_code.co_name == 'run':
                 f_locals = f.f_locals
                 f_self = f_locals.get('self')
-                if isinstance(f_self, ansible_mitogen.mixins.ActionModuleMixin):
+                if isinstance(f_self, ansible_mitogen.mixins.ActionModuleMixin) or (self._play_context.connection == 'httpapi' and isinstance(f_self, ActionModule)):
                     # backref for python interpreter discovery, should be safe because _get_task_vars
                     # is always called before running interpreter discovery
                     self._action = f_self
diff --git a/ansible_mitogen/plugins/connection/mitogen_ssh.py b/ansible_mitogen/plugins/connection/mitogen_ssh.py
index 75f2d42f..d977b6fd 100644
--- a/ansible_mitogen/plugins/connection/mitogen_ssh.py
+++ b/ansible_mitogen/plugins/connection/mitogen_ssh.py
@@ -75,7 +75,7 @@ import ansible_mitogen.loaders
 
 class Connection(ansible_mitogen.connection.Connection):
     transport = 'ssh'
-    vanilla_class = ansible_mitogen.loaders.connection_loader__get(
+    (vanilla_class, _) = ansible_mitogen.loaders.connection_loader__get(
         'ssh',
         class_only=True,
     )

dvwh avatar Jul 09 '24 10:07 dvwh

Helped with zabbix module. Plz include in next release

timansky avatar Jul 16 '24 00:07 timansky

#1215 fixed this, thanks!

nerijus avatar Jan 20 '25 18:01 nerijus

New release v0.3.21 includes #1215.

moreati avatar Jan 20 '25 20:01 moreati