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
5b652059
Commit
5b652059
authored
1 year ago
by
Pino, Adrián
Browse files
Options
Downloads
Patches
Plain Diff
Changes in playbook.py. Making ansible return JSON
parent
6ce83f8a
No related branches found
No related tags found
2 merge requests
!38
Nat 189 ansible return json
,
!37
Changes in playbook.py. Making ansible return JSON
Pipeline
#83741
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
+22
-4
22 additions, 4 deletions
lso/playbook.py
with
22 additions
and
4 deletions
lso/playbook.py
+
22
−
4
View file @
5b652059
"""
Module that gathers common API responses and data models.
"""
"""
Module that gathers common API responses and data models.
"""
import
json
import
enum
import
enum
import
logging
import
logging
import
threading
import
threading
...
@@ -66,17 +67,34 @@ def _run_playbook_proc(job_id: str, playbook_path: str, extra_vars: dict, invent
...
@@ -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 callback: Callback URL to PUT to when execution is completed.
:param [str] inventory: Ansible inventory to run the playbook against.
: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
=
[
payload
=
[
{
{
"
pp_run_results
"
:
{
"
pp_run_results
"
:
{
"
status
"
:
ansible_playbook_run
.
status
,
"
status
"
:
ansible_playbook_run
.
status
,
"
job_id
"
:
job_id
,
"
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
)
,
"
return_code
"
:
int
(
ansible_playbook_run
.
rc
)
},
},
"
confirm
"
:
"
ACCEPTED
"
,
"
confirm
"
:
"
ACCEPTED
"
}
}
]
]
...
...
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