From 3ccc156db82a709c34b373b19b9b3420e2f54ef3 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 4 Dec 2024 21:39:50 +0100 Subject: [PATCH] Prevent crash if Mode isn't present, which happens for Swarm jobs. (#1003) (cherry picked from commit 7583ea82acccf8aa898e3dd2fee022031e8eb072) --- changelogs/fragments/1003-docker_swarm_info-crash.yml | 2 ++ plugins/modules/docker_swarm_info.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/1003-docker_swarm_info-crash.yml diff --git a/changelogs/fragments/1003-docker_swarm_info-crash.yml b/changelogs/fragments/1003-docker_swarm_info-crash.yml new file mode 100644 index 000000000..6f6983a62 --- /dev/null +++ b/changelogs/fragments/1003-docker_swarm_info-crash.yml @@ -0,0 +1,2 @@ +bugfixes: + - "docker_swarm_info - do not crash when finding Swarm jobs if ``services=true`` (https://github.com/ansible-collections/community.docker/issues/1003)." diff --git a/plugins/modules/docker_swarm_info.py b/plugins/modules/docker_swarm_info.py index 6c6008dcf..641a5f019 100644 --- a/plugins/modules/docker_swarm_info.py +++ b/plugins/modules/docker_swarm_info.py @@ -270,7 +270,7 @@ def get_docker_items_list(self, docker_object=None, filters=None): item_record = self.get_essential_facts_tasks(item) elif docker_object == 'services': item_record = self.get_essential_facts_services(item) - if item_record['Mode'] == 'Global': + if item_record.get('Mode') == 'Global': item_record['Replicas'] = len(items) items_list.append(item_record)