From 1bb98542d3b2bcd804e59ba781b556d7388301cd Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Sun, 15 Mar 2015 11:22:07 -0700 Subject: [PATCH] Fix a potential bug in docker pull --- lib/ansible/modules/cloud/docker/docker.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index a730943fe5..d22d0027a2 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -1159,9 +1159,11 @@ class DockerManager(object): except Exception as e: self.module.fail_json(msg="failed to login to the remote registry, check your username/password.", error=repr(e)) try: - last = None - for line in self.client.pull(image, tag=tag, stream=True, **extra_params): - last = line + changes = list(self.client.pull(image, tag=tag, stream=True, **extra_params)) + try: + last = changes[-1] + except IndexError: + last = '{}' status = json.loads(last).get('status', '') if status.startswith('Status: Image is up to date for'): # Image is already up to date. Don't increment the counter. @@ -1171,7 +1173,7 @@ class DockerManager(object): self.increment_counter('pulled') else: # Unrecognized status string. - self.module.fail_json(msg="Unrecognized status from pull.", status=status) + self.module.fail_json(msg="Unrecognized status from pull.", status=status, changes=changes) except Exception as e: self.module.fail_json(msg="Failed to pull the specified image: %s" % resource, error=repr(e))