Repository: ansible/ansible-modules-core

Issue:
Add support for docker labels
I can come up with a PR, but I already have 2 from March 22 that were not merged yet.



Discussion:
+1

+1

@bobrik I can't find any PR's from you on this. If you have a patch I would LOVE this functionality as I don't name my containers and need to differentiate with Prometheus. 

Let me know if there is a PR I can throw a fat +1 at :yum:

@smashwilson this would also be nice if you have time :smile: 

@MrMMorris I have tho PRs hanging from Mar 22, can't see any reason to add more. Anyway, check out [collectd-docker](https://github.com/bobrik/collectd-docker) it might be sufficient for you :)

+1

+1

:+1: 

has there been any progress on this?

Someone please review.


Resolving patch:
diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py
--- a/cloud/docker/docker.py
+++ b/cloud/docker/docker.py
@@ -326,6 +326,12 @@
     default: false
     aliases: []
     version_added: "2.0"
+  labels:
+    description:
+      - Set container labels. Requires docker >= 1.6 and docker-py >= 1.2.0.
+    required: false
+    default: null
+    version_added: "1.9.4"
 author:
     - "Cove Schneider (@cove)"
     - "Joshua Conner (@joshuaconner)"
@@ -603,6 +609,7 @@ class DockerManager(object):
             'cap_add': ((0, 5, 0), '1.14'),
             'cap_drop': ((0, 5, 0), '1.14'),
             'read_only': ((1, 0, 0), '1.17'),
+            'labels': ((1, 2, 0), '1.18'),
             # Clientside only
             'insecure_registry': ((0, 5, 0), '0.0')
             }
@@ -1129,6 +1136,22 @@ def get_differing_containers(self):
                 differing.append(container)
                 continue
 
+            # LABELS
+
+            expected_labels = {}
+            for name, value in self.module.params.get('labels').iteritems():
+                expected_labels[name] = str(value)
+
+            actual_labels = {}
+            for container_label in container['Config']['Labels'] or []:
+                name, value = container_label.split('=', 1)
+                actual_labels[name] = value
+
+            if actual_labels != expected_labels:
+                self.reload_reasons.append('labels {0} => {1}'.format(actual_labels, expected_labels))
+                differing.append(container)
+                continue
+
             # HOSTNAME
 
             expected_hostname = self.module.params.get('hostname')
@@ -1425,6 +1448,7 @@ def create_containers(self, count=1):
                   'ports':        self.exposed_ports,
                   'volumes':      self.volumes,
                   'environment':  self.env,
+                  'labels':       self.module.params.get('labels'),
                   'hostname':     self.module.params.get('hostname'),
                   'domainname':   self.module.params.get('domainname'),
                   'detach':       self.module.params.get('detach'),
@@ -1679,6 +1703,7 @@ def main():
             cap_add         = dict(default=None, type='list'),
             cap_drop        = dict(default=None, type='list'),
             read_only       = dict(default=None, type='bool'),
+            labels          = dict(default={}, type='dict'),
         ),
         required_together = (
             ['tls_client_cert', 'tls_client_key'],


Test patch: