From ef6b437d0d00c50c0c9b012c70aa1293c2a94374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gross?= Date: Tue, 25 Mar 2014 14:50:29 +0100 Subject: [PATCH] Fix TypeError when using old simplejson lib. On some very old simplejson does not support the 'encoding' and give following exception: TypeError: __init__() got an unexpected keyword argument 'encoding' This fix runs json.dump with no encoding key (such as before #a023cb) on TypeError exception only. --- lib/ansible/module_utils/basic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 64d536d2627..2dcb9cd5458 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')