On se lance dans les scripts Python ! :-)
authorProgfou <jean-christophe.andre@auf.org>
Fri, 12 Feb 2016 16:35:30 +0000 (11:35 -0500)
committerProgfou <jean-christophe.andre@auf.org>
Fri, 12 Feb 2016 16:35:30 +0000 (11:35 -0500)
scripts/ansible-debian-versions [new file with mode: 0755]

diff --git a/scripts/ansible-debian-versions b/scripts/ansible-debian-versions
new file mode 100755 (executable)
index 0000000..804a556
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import ansible.runner
+from time import strftime
+
+release_color = {
+  "8": "00ae00", "7": "e6ff00", "6": "ff950e", "5": "ff420e",
+}
+default_release_color = "ff0000"
+unknown_release_color = "f0f0f0"
+
+pm = ansible.runner.Runner(module_name='setup', timeout=5, subset='all')
+out = pm.run()
+
+#import json
+#file('/tmp/out.json', 'w').write(json.dumps(out, sort_keys=True, indent=4, separators=(',', ': ')))
+
+server_list = []
+for server,data in out['contacted'].items():
+    if 'ansible_facts' in data and 'ansible_lsb' in data['ansible_facts']:
+        lsb_data = data['ansible_facts']['ansible_lsb']
+        server_list.append({
+            'name': server,
+            'description': lsb_data['description'],
+            'major_release': lsb_data['major_release'],
+        })
+    else:
+        server_list.append({
+            'name': server,
+            'description': 'inconnue (information non disponible)',
+            'major_release': '0',
+        })
+for server,data in out['dark'].items():
+        server_list.append({
+            'name': server,
+            'description': 'inconnue (échec de connexion)',
+            'major_release': '0',
+        })
+
+server_list.sort(key=lambda x: '%03d-%s' % (int(x['major_release']),x['name']))
+
+print "||<tablebgcolor=\"#cccccc\">'''Serveur'''||'''Version Debian au %s'''||" % strftime('%Y-%m-%d')
+for server in server_list:
+    if server['major_release'] == '0':
+        server['color'] = unknown_release_color
+    elif server['major_release'] in release_color:
+        server['color'] = release_color[server['major_release']]
+    else:
+        server['color'] = default_release_color
+    print "||<rowbgcolor=\"#%(color)s\">%(name)s||%(description)s||" % server
+print "(tableau généré via le script [[http://git.auf.org/?p=ansible.git;a=blob;f=scripts/ansible-debian-versions|ansible-debian-versions]])"