forked from openedx-unsupported/configuration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible_msg.py
executable file
·42 lines (32 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
#!/usr/bin/env python3.6
"""Simple utility for deciphering Ansible jsonized task output."""
from __future__ import absolute_import
from __future__ import print_function
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()
# junk:
# '==> default: failed: [localhost] (item=/edx/app/edx_ansible/edx_ansible/requirements.txt) => {"cmd": "/edx/app/edx...'
print(("Stdin is {} chars: {!r}...{!r}".format(len(junk), junk[:40], junk[-40:])))
junk = junk.replace('\n', '')
junk = junk[junk.index('=> {')+3:]
junk = junk[:junk.rindex('}')+1]
data = json.loads(junk)
GOOD_KEYS = ['cmd', 'msg', 'stdout', 'stderr', 'module_stdout', 'module_stderr', 'warnings']
for key in GOOD_KEYS:
if data.get(key):
print(f"== {key} ===========================")
print((data[key]))
BAD_KEYS = ['stdout_lines', 'start', 'end', 'delta', 'changed', 'failed', 'rc', 'item']
unknown_keys = set(data) - set(GOOD_KEYS) - set(BAD_KEYS)
if unknown_keys:
print("== Unknown keys ======================")
for key in unknown_keys:
print(f"{key}: {data[key]!r:80}")