Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LSO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
LSO
Commits
f1ac14cd
Verified
Commit
f1ac14cd
authored
1 year ago
by
Karel van Klink
Browse files
Options
Downloads
Patches
Plain Diff
Make Ansible output less verbose
parent
cae69945
No related branches found
No related tags found
1 merge request
!39
Feature/nat 231 improve performance
Pipeline
#83779
failed
1 year ago
Stage: tox
Stage: documentation
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lso/playbook.py
+40
-2
40 additions, 2 deletions
lso/playbook.py
with
40 additions
and
2 deletions
lso/playbook.py
+
40
−
2
View file @
f1ac14cd
...
...
@@ -79,12 +79,50 @@ def _run_playbook_proc(job_id: str, playbook_path: str, extra_vars: dict, invent
json_content
=
json_output
.
read
()
parsed_output
=
[]
too_verbose_keys
=
[
"
_ansible_no_log
"
,
"
_ansible_delegated_vars
"
,
"
_ansible_verbose_always
"
,
"
ansible_facts
"
,
"
changed
"
,
"
file
"
,
"
invocation
"
,
"
include
"
,
"
include_args
"
,
]
for
line
in
json_content
.
strip
().
splitlines
():
try
:
task_output
=
json
.
loads
(
line
)
task_output
.
pop
(
"
stdout
"
,
None
)
parsed_output
.
append
(
task_output
)
if
"
res
"
in
task_output
[
"
event_data
"
]
and
(
task_output
[
"
event_data
"
][
"
res
"
][
"
changed
"
]
is
True
or
int
(
ansible_playbook_run
.
rc
)
!=
0
):
# The line contains result data, and must either consist of a change, or the playbook failed, and we
# want all steps, including those that didn't make changes.
task_result
=
task_output
[
"
event_data
"
][
"
res
"
]
# Remove redundant ansible-related keys.
for
remove
in
too_verbose_keys
:
task_result
.
pop
(
remove
,
None
)
# Remove meta-steps that just copy some temporary files, and continue to the next event
if
"
state
"
in
task_result
:
if
task_result
[
"
state
"
]
==
"
directory
"
or
task_result
[
"
state
"
]
==
"
file
"
:
continue
if
"
diff_lines
"
in
task_result
:
# Prevent the diff from being displayed twice, and only keep the formatted version.
task_result
.
pop
(
"
diff
"
,
None
)
if
bool
(
task_result
):
# Only add the event if there are any relevant keys left.
parsed_output
.
append
({
"
host
"
:
task_output
[
"
event_data
"
][
"
host
"
]}
|
task_result
)
elif
"
ok
"
in
task_output
[
"
event_data
"
]:
# Always include the final message that contains the playbook execution overview.
parsed_output
.
append
(
task_output
[
"
event_data
"
])
except
json
.
JSONDecodeError
:
# If the line cannot be decoded as JSON, include it in its entirety.
parsed_output
.
append
({
"
invalid_json
"
:
line
})
payload
=
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment