diff --git a/changelogs/fragments/inventory-docker-service-stack-groups.yaml b/changelogs/fragments/inventory-docker-service-stack-groups.yaml new file mode 100644 index 00000000000..f48ae18cebc --- /dev/null +++ b/changelogs/fragments/inventory-docker-service-stack-groups.yaml @@ -0,0 +1,2 @@ +minor_changes: + - inventory/docker - Group containers by docker-swarm "service" and "stack" diff --git a/contrib/inventory/docker.py b/contrib/inventory/docker.py index ba221ff4347..1b92b4c5275 100755 --- a/contrib/inventory/docker.py +++ b/contrib/inventory/docker.py @@ -196,6 +196,8 @@ When run in --list mode (the default), container instances are grouped by: - container name - container short id - image_name (image_) + - stack_name (stack_) + - service_name (service_) - docker_host - running - stopped @@ -622,6 +624,14 @@ class DockerInventory(object): if image_name: self.groups["image_%s" % (image_name)].append(name) + stack_name = inspect.get('Config', dict()).get('Labels', dict()).get('com.docker.stack.namespace') + if stack_name: + self.groups["stack_%s" % stack_name].append(name) + + service_name = inspect.get('Config', dict()).get('Labels', dict()).get('com.docker.swarm.service.name') + if service_name: + self.groups["service_%s" % service_name].append(name) + self.groups[id].append(name) self.groups[name].append(name) if short_id not in self.groups: