From 93b620ea8a606d41a5876b1097fff4624a9194bb Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Tue, 24 Mar 2015 11:07:12 -0400 Subject: [PATCH] Compare container images to Config.Image. --- lib/ansible/modules/cloud/docker/docker.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index 8a52be3bc45..41cdd0b2526 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -424,6 +424,13 @@ def get_split_image_tag(image): return resource, tag +def normalize_image(image): + """ + Normalize a Docker image name to include the implied :latest tag. + """ + + return ":".join(get_split_image_tag(image)) + def is_running(container): '''Return True if an inspected container is in a state we consider "running."''' @@ -1113,11 +1120,13 @@ class DockerManager(object): if inspected: repo_tags = self.get_image_repo_tags() else: - image, tag = get_split_image_tag(self.module.params.get('image')) - repo_tags = [':'.join([image, tag])] + repo_tags = [normalize_image(self.module.params.get('image'))] for i in self.client.containers(all=True): - running_image = i['Image'] + details = self.client.inspect_container(i['Id']) + details = _docker_id_quirk(details) + + running_image = normalize_image(details['Config']['Image']) running_command = i['Command'].strip() if name: @@ -1132,9 +1141,6 @@ class DockerManager(object): matches = image_matches and command_matches if matches: - details = self.client.inspect_container(i['Id']) - details = _docker_id_quirk(details) - deployed.append(details) return deployed