Ajout d'infos d'archi et virtualisation.
[ansible.git] / scripts / ansible-debian-versions
... / ...
CommitLineData
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3import ansible.runner
4from time import strftime
5
6# constantes
7
8URL = "http://git.auf.org/?p=ansible.git;a=blob;f=scripts/ansible-debian-versions"
9
10release_color = {
11 "8": "00ae00", "7": "e6ff00", "6": "ff950e", "5": "ff420e",
12}
13default_release_color = "ff0000"
14unknown_release_color = "f0f0f0"
15
16# collecte des données
17
18pm = ansible.runner.Runner(module_name='setup', timeout=5, subset='all')
19out = pm.run()
20
21# sauvegarde temporaire pour débogage
22
23import json
24file('/tmp/out.json', 'w').write(json.dumps(out, sort_keys=True, indent=4, separators=(',', ': ')))
25
26# traitement des données
27
28server_list = []
29
30for server,data in out['contacted'].items():
31 data['name'] = server
32 facts = data['ansible_facts']
33 if 'ansible_lsb' in facts:
34 lsb_data = data['ansible_facts']['ansible_lsb']
35 data['description'] = lsb_data['description']
36 data['major_release'] = lsb_data['major_release']
37 else:
38 data['description'] = 'inconnue (information non disponible)'
39 data['major_release'] = '0'
40 if 'ansible_virtualization_type' in facts and \
41 'ansible_virtualization_role' in facts:
42 virtual_info = facts['ansible_virtualization_type'] \
43 + ' / ' + facts['ansible_virtualization_role']
44 if virtual_info == 'NA / NA':
45 virtual_info = "physique"
46 if facts['ansible_virtualization_role'] != 'guest':
47 virtual_info = "'''" + virtual_info + "'''"
48 virtual_info = virtual_info.replace('host', 'hôte')
49 virtual_info = virtual_info.replace('guest', 'invité')
50 data['virtual_info'] = virtual_info
51 else:
52 data['virtual_info'] = 'inconnu'
53 if 'ansible_machine' in facts and 'ansible_userspace_bits' in facts:
54 data['architecture'] = facts['ansible_userspace_bits'] + ' bits' \
55 + ' / ' + facts['ansible_machine']
56 else:
57 data['architecture'] = 'inconnue'
58 server_list.append({
59 'name': data['name'],
60 'description': data['description'],
61 'major_release': data['major_release'],
62 'architecture': data['architecture'],
63 'virtual_info': data['virtual_info'],
64 })
65
66for server,data in out['dark'].items():
67 server_list.append({
68 'name': server,
69 'description': 'inconnue (échec de connexion)',
70 'major_release': '0',
71 'architecture': 'inconnu',
72 'virtual_info': 'inconnu',
73 })
74
75# tri de la liste des serveurs par version de distribution croissante
76
77server_list.sort(key=lambda x: '%03d-%s' % (int(x['major_release']),x['name']))
78
79# affichage du code wiki MoinMoin correspondant
80
81print "||<tablebgcolor=\"#cccccc\">'''Serveur'''||'''Version du système au %s'''||'''Architecture'''||'''Virtualisation'''||" % strftime('%Y-%m-%d')
82
83for server in server_list:
84 if server['major_release'] == '0':
85 server['color'] = unknown_release_color
86 elif server['major_release'] in release_color:
87 server['color'] = release_color[server['major_release']]
88 else:
89 server['color'] = default_release_color
90 print "||<rowbgcolor=\"#%(color)s\">%(name)s||%(description)s||%(architecture)s||%(virtual_info)s||" % server
91
92print "(tableau généré via le script [[%s|ansible-debian-versions]])" % URL