Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
configuration
Commits
8787ae7b
Commit
8787ae7b
authored
Apr 04, 2018
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ansible_msg.py: Utility for deciphering Ansible task output
parent
a34aa3fa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
util/ansible_msg.py
+40
-0
No files found.
util/ansible_msg.py
0 → 100755
View file @
8787ae7b
#!/usr/bin/env python3.6
"""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
()
# 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}"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment