2929from __future__ import absolute_import , division , print_function
3030__metaclass__ = type
3131
32+ import json
3233import logging
3334import os
3435import pwd
4243
4344from ansible .module_utils .common .text .converters import to_bytes , to_text
4445from ansible .module_utils .six .moves import shlex_quote
45- from ansible .parsing .utils .jsonify import jsonify
4646
4747import mitogen .core
4848import mitogen .select
@@ -219,8 +219,13 @@ def _transfer_data(self, remote_path, data):
219219 Used by the base _execute_module(), and in <2.4 also by the template
220220 action module, and probably others.
221221 """
222+ if data is None and ansible_mitogen .utils .ansible_version [:2 ] <= (2 , 18 ):
223+ data = '{}'
222224 if isinstance (data , dict ):
223- data = jsonify (data )
225+ try :
226+ data = json .dumps (data , ensure_ascii = False )
227+ except UnicodeDecodeError :
228+ data = json .dumps (data )
224229 if not isinstance (data , bytes ):
225230 data = to_bytes (data , errors = 'surrogate_or_strict' )
226231
@@ -402,15 +407,17 @@ def _execute_module(self, module_name=None, module_args=None, tmp=None,
402407 if not self ._mitogen_rediscovered_interpreter :
403408 result ['ansible_facts' ][self ._discovered_interpreter_key ] = self ._discovered_interpreter
404409
405- if self ._discovery_warnings :
410+ discovery_warnings = getattr (self , '_discovery_warnings' , [])
411+ if discovery_warnings :
406412 if result .get ('warnings' ) is None :
407413 result ['warnings' ] = []
408- result ['warnings' ].extend (self . _discovery_warnings )
414+ result ['warnings' ].extend (discovery_warnings )
409415
410- if self ._discovery_deprecation_warnings :
416+ discovery_deprecation_warnings = getattr (self , '_discovery_deprecation_warnings' , [])
417+ if discovery_deprecation_warnings :
411418 if result .get ('deprecations' ) is None :
412419 result ['deprecations' ] = []
413- result ['deprecations' ].extend (self . _discovery_deprecation_warnings )
420+ result ['deprecations' ].extend (discovery_deprecation_warnings )
414421
415422 return ansible .utils .unsafe_proxy .wrap_var (result )
416423
@@ -429,7 +436,10 @@ def _postprocess_response(self, result):
429436 "stderr": "stderr data"
430437 }
431438 """
432- data = self ._parse_returned_data (result )
439+ if ansible_mitogen .utils .ansible_version [:2 ] >= (2 , 19 ):
440+ data = self ._parse_returned_data (result , profile = 'legacy' )
441+ else :
442+ data = self ._parse_returned_data (result )
433443
434444 # Cutpasted from the base implementation.
435445 if 'stdout' in data and 'stdout_lines' not in data :
0 commit comments