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
Merge requests
!37
Changes in playbook.py. Making ansible return JSON
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Changes in playbook.py. Making ansible return JSON
NAT-189-ansible-return-json
into
develop
Overview
0
Commits
1
Pipelines
1
Changes
1
Closed
Pino, Adrián
requested to merge
NAT-189-ansible-return-json
into
develop
1 year ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
5b652059
1 commit,
1 year ago
1 file
+
22
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
lso/playbook.py
+
22
−
4
Options
"""
Module that gathers common API responses and data models.
"""
import
json
import
enum
import
logging
import
threading
@@ -66,17 +67,34 @@ def _run_playbook_proc(job_id: str, playbook_path: str, extra_vars: dict, invent
:param str callback: Callback URL to PUT to when execution is completed.
:param [str] inventory: Ansible inventory to run the playbook against.
"""
ansible_playbook_run
=
ansible_runner
.
run
(
playbook
=
playbook_path
,
inventory
=
inventory
,
extravars
=
extra_vars
)
ansible_playbook_run
=
ansible_runner
.
run
(
playbook
=
playbook_path
,
inventory
=
inventory
,
extravars
=
extra_vars
,
json_mode
=
True
)
# Process playbook JSON stdout
json_output
=
ansible_playbook_run
.
stdout
json_content
=
json_output
.
read
()
parsed_output
=
[]
for
line
in
json_content
.
strip
().
splitlines
():
try
:
task_output
=
json
.
loads
(
line
)
parsed_output
.
append
(
task_output
)
except
json
.
JSONDecodeError
as
e
:
pass
# Skip empty line
payload
=
[
{
"
pp_run_results
"
:
{
"
status
"
:
ansible_playbook_run
.
status
,
"
job_id
"
:
job_id
,
"
output
"
:
str
(
ansible_playbook_run
.
stdout
.
read
()
),
"
return_code
"
:
int
(
ansible_playbook_run
.
rc
)
,
"
output
"
:
json
.
dumps
(
parsed_output
,
indent
=
4
),
"
return_code
"
:
int
(
ansible_playbook_run
.
rc
)
},
"
confirm
"
:
"
ACCEPTED
"
,
"
confirm
"
:
"
ACCEPTED
"
}
]
Loading