summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2018-11-16 12:11:33 -0500
committeransibot <ansibot@users.noreply.github.com>2018-11-16 12:11:33 -0500
commit3132266aa195f0d086550ead3c34cd94e3b14085 (patch)
tree6ac6237f9b2dce0e9b6c6ed0da1d3ce2c4f06667 /bin
parent86be0566333744c98c003a0910adda86faa60e14 (diff)
downloadansible-3132266aa195f0d086550ead3c34cd94e3b14085.zip
use ansible json encoding/decoding to avoid errors (#47214)
tackle known issues with (de)serializing certain objects fixes #47200
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ansible-connection9
1 files changed, 5 insertions, 4 deletions
diff --git a/bin/ansible-connection b/bin/ansible-connection
index a06adcfc3b..59e15602bb 100755
--- a/bin/ansible-connection
+++ b/bin/ansible-connection
@@ -26,6 +26,7 @@ from ansible.module_utils.six import PY3
from ansible.module_utils.six.moves import cPickle, StringIO
from ansible.module_utils.connection import Connection, ConnectionError, send_data, recv_data
from ansible.module_utils.service import fork_process
+from ansible.parsing.ajson import AnsibleJSONEncoder, AnsibleJSONDecoder
from ansible.playbook.play_context import PlayContext
from ansible.plugins.loader import connection_loader
from ansible.utils.path import unfrackpath, makedirs_safe
@@ -115,7 +116,7 @@ class ConnectionProcess(object):
result['exception'] = traceback.format_exc()
finally:
result['messages'] = messages
- self.fd.write(json.dumps(result))
+ self.fd.write(json.dumps(result, cls=AnsibleJSONEncoder))
self.fd.close()
def run(self):
@@ -275,7 +276,7 @@ def main():
else:
os.close(w)
rfd = os.fdopen(r, 'r')
- data = json.loads(rfd.read())
+ data = json.loads(rfd.read(), cls=AnsibleJSONDecoder)
messages.extend(data.pop('messages'))
result.update(data)
@@ -306,10 +307,10 @@ def main():
sys.stdout = saved_stdout
if 'exception' in result:
rc = 1
- sys.stderr.write(json.dumps(result))
+ sys.stderr.write(json.dumps(result, cls=AnsibleJSONEncoder))
else:
rc = 0
- sys.stdout.write(json.dumps(result))
+ sys.stdout.write(json.dumps(result, cls=AnsibleJSONEncoder))
sys.exit(rc)