From 2dde45cea905d2433b66d80ff7da6fb3ef712eac Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Tue, 24 Mar 2015 11:18:15 -0400 Subject: [PATCH] Only fetch details when necessary. --- lib/ansible/modules/cloud/docker/docker.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index 41cdd0b2526..632ed07d087 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -1123,15 +1123,17 @@ class DockerManager(object): repo_tags = [normalize_image(self.module.params.get('image'))] for i in self.client.containers(all=True): - details = self.client.inspect_container(i['Id']) - details = _docker_id_quirk(details) - - running_image = normalize_image(details['Config']['Image']) - running_command = i['Command'].strip() + details = None if name: matches = name in i.get('Names', []) else: + details = self.client.inspect_container(i['Id']) + details = _docker_id_quirk(details) + + running_image = normalize_image(details['Config']['Image']) + running_command = i['Command'].strip() + image_matches = running_image in repo_tags # if a container has an entrypoint, `command` will actually equal @@ -1141,6 +1143,10 @@ class DockerManager(object): matches = image_matches and command_matches if matches: + if not details: + details = self.client.inspect_container(i['Id']) + details = _docker_id_quirk(details) + deployed.append(details) return deployed