Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpapi connection support #1086

Open
dvwh opened this issue Jul 4, 2024 · 2 comments
Open

httpapi connection support #1086

dvwh opened this issue Jul 4, 2024 · 2 comments

Comments

@dvwh
Copy link

dvwh commented Jul 4, 2024

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
Copy link
Author

dvwh commented Jul 9, 2024

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,
     )

@timansky
Copy link

Helped with zabbix module. Plz include in next release

timansky added a commit to timansky/mitogen that referenced this issue Jul 16, 2024
timansky added a commit to timansky/mitogen that referenced this issue Oct 1, 2024
timansky added a commit to timansky/mitogen that referenced this issue Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants