On se lance dans les scripts Python ! :-)
[ansible.git] / scripts / ansible-debian-versions
CommitLineData
28212351
P
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3import ansible.runner
4from time import strftime
5
6release_color = {
7 "8": "00ae00", "7": "e6ff00", "6": "ff950e", "5": "ff420e",
8}
9default_release_color = "ff0000"
10unknown_release_color = "f0f0f0"
11
12pm = ansible.runner.Runner(module_name='setup', timeout=5, subset='all')
13out = pm.run()
14
15#import json
16#file('/tmp/out.json', 'w').write(json.dumps(out, sort_keys=True, indent=4, separators=(',', ': ')))
17
18server_list = []
19for server,data in out['contacted'].items():
20 if 'ansible_facts' in data and 'ansible_lsb' in data['ansible_facts']:
21 lsb_data = data['ansible_facts']['ansible_lsb']
22 server_list.append({
23 'name': server,
24 'description': lsb_data['description'],
25 'major_release': lsb_data['major_release'],
26 })
27 else:
28 server_list.append({
29 'name': server,
30 'description': 'inconnue (information non disponible)',
31 'major_release': '0',
32 })
33for server,data in out['dark'].items():
34 server_list.append({
35 'name': server,
36 'description': 'inconnue (échec de connexion)',
37 'major_release': '0',
38 })
39
40server_list.sort(key=lambda x: '%03d-%s' % (int(x['major_release']),x['name']))
41
42print "||<tablebgcolor=\"#cccccc\">'''Serveur'''||'''Version Debian au %s'''||" % strftime('%Y-%m-%d')
43for server in server_list:
44 if server['major_release'] == '0':
45 server['color'] = unknown_release_color
46 elif server['major_release'] in release_color:
47 server['color'] = release_color[server['major_release']]
48 else:
49 server['color'] = default_release_color
50 print "||<rowbgcolor=\"#%(color)s\">%(name)s||%(description)s||" % server
51print "(tableau généré via le script [[http://git.auf.org/?p=ansible.git;a=blob;f=scripts/ansible-debian-versions|ansible-debian-versions]])"