1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Docker inventory service/stack groups for docker swarm (#48021)

* Adding service and stack grouping to docker inventory

* Updating documentation

* Adding changelog fragment for docker.py inventory script
This commit is contained in:
Eric Miller 2018-12-17 05:58:26 -06:00 committed by John R Barker
parent 87ee59b8d7
commit 4d0f2e632c
2 changed files with 12 additions and 0 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- inventory/docker - Group containers by docker-swarm "service" and "stack"

View file

@ -196,6 +196,8 @@ When run in --list mode (the default), container instances are grouped by:
- container name
- container short id
- image_name (image_<image name>)
- stack_name (stack_<stack name>)
- service_name (service_<service name>)
- 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: