diff --git a/lib/ansible/module_utils/docker_common.py b/lib/ansible/module_utils/docker_common.py index e19e855089..bdf64d0cfd 100644 --- a/lib/ansible/module_utils/docker_common.py +++ b/lib/ansible/module_utils/docker_common.py @@ -430,9 +430,13 @@ class AnsibleDockerClient(Client): Pull an image ''' self.log("Pulling image %s:%s" % (name, tag)) + alreadyToLatest = False try: for line in self.pull(name, tag=tag, stream=True, decode=True): self.log(line, pretty_print=True) + if line.get('status'): + if line.get('status').startswith('Status: Image is up to date for'): + alreadyToLatest = True if line.get('error'): if line.get('errorDetail'): error_detail = line.get('errorDetail') @@ -444,6 +448,6 @@ class AnsibleDockerClient(Client): except Exception as exc: self.fail("Error pulling image %s:%s - %s" % (name, tag, str(exc))) - return self.find_image(name, tag) + return self.find_image(name, tag), alreadyToLatest diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py index 82684890d0..7625deabb4 100644 --- a/lib/ansible/modules/cloud/docker/docker_container.py +++ b/lib/ansible/modules/cloud/docker/docker_container.py @@ -1748,9 +1748,12 @@ class ContainerManager(DockerBaseClass): if not self.check_mode: if not image or self.parameters.pull: self.log("Pull the image.") - image = self.client.pull_image(repository, tag) - self.results['actions'].append(dict(pulled_image="%s:%s" % (repository, tag))) - self.results['changed'] = True + image, alreadyToLatest = self.client.pull_image(repository, tag) + if alreadyToLatest: + self.results['changed'] = False + else: + self.results['changed'] = True + self.results['actions'].append(dict(pulled_image="%s:%s" % (repository, tag))) self.log("image") self.log(image, pretty_print=True) return image