diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 64d536d262..2dcb9cd545 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -884,6 +884,9 @@ class AnsibleModule(object): for encoding in ("utf-8", "latin-1", "unicode_escape"): try: return json.dumps(data, encoding=encoding) + # Old systems using simplejson module does not support encoding keyword. + except TypeError, e: + return json.dumps(data) except UnicodeDecodeError, e: continue self.fail_json(msg='Invalid unicode encoding encountered')