From c2bf2c7c54e60fc205cb870ee2c872275f6fa4a8 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 4 May 2015 10:16:01 -0700 Subject: [PATCH] Fix error when container has no names. Rename loop variable from "i" to more informative "container" Fixes #1188 --- lib/ansible/modules/cloud/docker/docker.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index de89331def..8116092809 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -1131,17 +1131,20 @@ class DockerManager(object): else: repo_tags = [normalize_image(self.module.params.get('image'))] - for i in self.client.containers(all=True): + for container in self.client.containers(all=True): details = None if name: - matches = name in i.get('Names', []) + name_list = container.get('Names') + if name_list is None: + name_list = [] + matches = name in name_list 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() + running_command = container['Command'].strip() image_matches = running_image in repo_tags @@ -1153,7 +1156,7 @@ class DockerManager(object): if matches: if not details: - details = self.client.inspect_container(i['Id']) + details = self.client.inspect_container(container['Id']) details = _docker_id_quirk(details) deployed.append(details)