From 2653bd3f50c91fcc5cfa3e81d1f48e43555d41af Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 18 May 2018 20:15:58 +0200 Subject: [PATCH] Fix docker_image archive features to work with Python 3 Without binary mode, ansible shows a "write() argument must be str, not bytes" error when using Python 3. --- lib/ansible/modules/cloud/docker/docker_image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker_image.py b/lib/ansible/modules/cloud/docker/docker_image.py index 7dacf1c76a3..bc8e1f29c66 100644 --- a/lib/ansible/modules/cloud/docker/docker_image.py +++ b/lib/ansible/modules/cloud/docker/docker_image.py @@ -402,7 +402,7 @@ class ImageManager(DockerBaseClass): self.fail("Error getting image %s - %s" % (image_name, str(exc))) try: - with open(self.archive_path, 'w') as fd: + with open(self.archive_path, 'wb') as fd: if HAS_DOCKER_PY_3: for chunk in image: fd.write(chunk) @@ -553,7 +553,7 @@ class ImageManager(DockerBaseClass): ''' try: self.log("Opening image %s" % self.load_path) - image_tar = open(self.load_path, 'r') + image_tar = open(self.load_path, 'rb') except Exception as exc: self.fail("Error opening image %s - %s" % (self.load_path, str(exc)))