From: Claude Becker <becker@phys.ethz.ch>
Date: Thu, 24 Apr 2025 09:09:20 +0200
Subject: Ugly patch for ansible 12 data tagging

---
 ansible_mitogen/mixins.py | 23 ++++++++++++++---------
 ansible_mitogen/runner.py |  3 +++
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/ansible_mitogen/mixins.py b/ansible_mitogen/mixins.py
index dadf2c1..85220d3 100644
--- a/ansible_mitogen/mixins.py
+++ b/ansible_mitogen/mixins.py
@@ -402,15 +402,16 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
             if not self._mitogen_rediscovered_interpreter:
                 result['ansible_facts'][self._discovered_interpreter_key] = self._discovered_interpreter
 
-        if self._discovery_warnings:
-            if result.get('warnings') is None:
-                result['warnings'] = []
-            result['warnings'].extend(self._discovery_warnings)
+        if ansible_mitogen.utils.ansible_version[:2] < (2, 19):
+            if self._discovery_warnings:
+                if result.get('warnings') is None:
+                    result['warnings'] = []
+                result['warnings'].extend(self._discovery_warnings)
 
-        if self._discovery_deprecation_warnings:
-            if result.get('deprecations') is None:
-                result['deprecations'] = []
-            result['deprecations'].extend(self._discovery_deprecation_warnings)
+            if self._discovery_deprecation_warnings:
+                if result.get('deprecations') is None:
+                    result['deprecations'] = []
+                result['deprecations'].extend(self._discovery_deprecation_warnings)
 
         return ansible.utils.unsafe_proxy.wrap_var(result)
 
@@ -429,7 +430,11 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
                     "stderr": "stderr data"
                 }
         """
-        data = self._parse_returned_data(result)
+        if ansible_mitogen.utils.ansible_version[:2] >= (2, 19):
+            # Pass legacy serialization profile to Ansible 2.19+
+            data = self._parse_returned_data(result, 'legacy')
+        else:
+            data = self._parse_returned_data(result)
 
         # Cutpasted from the base implementation.
         if 'stdout' in data and 'stdout_lines' not in data:
diff --git a/ansible_mitogen/runner.py b/ansible_mitogen/runner.py
index b60e537..be54afa 100644
--- a/ansible_mitogen/runner.py
+++ b/ansible_mitogen/runner.py
@@ -76,6 +76,9 @@ except ImportError:
 import ansible.module_utils.basic
 ansible.module_utils.basic._ANSIBLE_ARGS = '{}'
 
+# Ugly patch for ansible data tagging https://github.com/ansible/ansible/pull/84621
+ansible.module_utils.basic._ANSIBLE_PROFILE = 'legacy'
+
 # For tasks that modify /etc/resolv.conf, non-Debian derivative glibcs cache
 # resolv.conf at startup and never implicitly reload it. Cope with that via an
 # explicit call to res_init() on each task invocation. BSD-alikes export it
