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
!38
Nat 189 ansible return json
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Nat 189 ansible return json
NAT-189-ansible-return-json
into
develop
Overview
0
Commits
3
Pipelines
2
Changes
9
Merged
Pino, Adrián
requested to merge
NAT-189-ansible-return-json
into
develop
2 years ago
Overview
0
Commits
3
Pipelines
2
Changes
9
Expand
0
0
Merge request reports
Compare
develop
version 1
95f4e54c
2 years ago
develop (base)
and
latest version
latest version
e3fb6ceb
3 commits,
2 years ago
version 1
95f4e54c
2 commits,
2 years ago
9 files
+
47
−
25
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
9
Search (e.g. *.vue) (Ctrl+P)
lso/playbook.py
+
20
−
2
Options
"""
Module that gathers common API responses and data models.
"""
import
enum
import
json
import
logging
import
threading
import
uuid
@@ -66,14 +67,31 @@ 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
:
parsed_output
.
append
({
"
invalid_json
"
:
line
})
payload
=
[
{
"
pp_run_results
"
:
{
"
status
"
:
ansible_playbook_run
.
status
,
"
job_id
"
:
job_id
,
"
output
"
:
str
(
ansible_playbook_run
.
stdout
.
read
()
),
"
output
"
:
json
.
dumps
(
parsed_output
,
indent
=
4
),
"
return_code
"
:
int
(
ansible_playbook_run
.
rc
),
},
"
confirm
"
:
"
ACCEPTED
"
,
Loading