forked from openedx-unsupported/configuration
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ansible_msg.py
executable file
·43 lines (33 loc) · 1.23 KB
/
ansible_msg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
"""Simple utility for deciphering Ansible jsonized task output."""
import json
import sys
if len(sys.argv) > 1:
f = open(sys.argv[1])
else:
if sys.stdin.isatty():
print("Copy one complete line of junk from ansible output, and pipe it to me.")
sys.exit()
f = sys.stdin
junk = f.read()
if not junk:
print("No message to decode.")
sys.exit()
# junk:
# '==> default: failed: [localhost] (item=/edx/app/edx_ansible/edx_ansible/requirements.txt) => {"cmd": "/edx/app/edx...'
junk = junk.replace('\n', '')
junk = junk[junk.index('=> {')+3:]
junk = junk[:junk.rindex('}')+1]
data = json.loads(junk)
# Order these so that the most likely useful messages are last.
GOOD_KEYS = ['cmd', 'module_stdout', 'module_stderr', 'warnings', 'msg', 'censored', 'stderr', 'stdout']
IGNORE_KEYS = ['stdout_lines', 'stderr_lines', 'start', 'end', 'delta', 'changed', 'failed', 'rc', 'item']
unknown_keys = set(data) - set(GOOD_KEYS) - set(IGNORE_KEYS)
if unknown_keys:
print("== Unknown keys ======================")
for key in unknown_keys:
print(f"{key}: {data[key]!r:80}")
for key in GOOD_KEYS:
if data.get(key):
print(f"== {key} ===========================")
print(data[key])