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
0dc1f3ce
Verified
Commit
0dc1f3ce
authored
1 year ago
by
Karel van Klink
Browse files
Options
Downloads
Patches
Plain Diff
add new dynamic endpoint for executing playbooks
parent
4f0f0e30
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lso/__init__.py
+4
-3
4 additions, 3 deletions
lso/__init__.py
lso/playbook.py
+8
-3
8 additions, 3 deletions
lso/playbook.py
lso/routes/default.py
+1
-1
1 addition, 1 deletion
lso/routes/default.py
lso/routes/playbook.py
+46
-0
46 additions, 0 deletions
lso/routes/playbook.py
with
59 additions
and
7 deletions
lso/__init__.py
+
4
−
3
View file @
0dc1f3ce
...
...
@@ -6,7 +6,7 @@ from fastapi import FastAPI
from
fastapi.middleware.cors
import
CORSMiddleware
from
lso
import
config
,
environment
from
lso.routes
import
default
,
ip_trunk
,
router
from
lso.routes
import
default
,
ip_trunk
,
playbook
,
router
def
create_app
()
->
FastAPI
:
...
...
@@ -25,14 +25,15 @@ def create_app() -> FastAPI:
)
app
.
include_router
(
default
.
router
,
prefix
=
"
/api
"
)
app
.
include_router
(
playbook
.
router
,
prefix
=
"
/api/playbook
"
)
app
.
include_router
(
router
.
router
,
prefix
=
"
/api/router
"
)
app
.
include_router
(
ip_trunk
.
router
,
prefix
=
"
/api/ip_trunk
"
)
# test that config params are loaded and available
config
.
load
()
logging
.
info
(
"
FastAPI app initialized
"
)
environment
.
setup_logging
()
logging
.
info
(
"
FastAPI app initialized
"
)
return
app
This diff is collapsed.
Click to expand it.
lso/playbook.py
+
8
−
3
View file @
0dc1f3ce
...
...
@@ -176,12 +176,17 @@ def _run_playbook_proc(
logger
.
error
(
msg
)
def
run_playbook
(
playbook_path
:
Path
,
extra_vars
:
dict
,
inventory
:
str
,
callback
:
HttpUrl
)
->
PlaybookLaunchResponse
:
def
run_playbook
(
playbook_path
:
Path
,
extra_vars
:
dict
[
str
,
Any
],
inventory
:
dict
[
str
,
Any
]
|
str
,
callback
:
HttpUrl
,
)
->
PlaybookLaunchResponse
:
"""
Run an Ansible playbook against a specified inventory.
:param Path playbook_path: playbook to be executed.
:param dict extra_vars: Any extra vars needed for the playbook to run.
:param
[str]
inventory: The inventory that the playbook is executed against.
:param dict
[str, Any]
extra_vars: Any extra vars needed for the playbook to run.
:param
dict[str, Any] | str
inventory: The inventory that the playbook is executed against.
:param :class:`HttpUrl` callback: Callback URL where the playbook should send a status update when execution is
completed. This is used for workflow-orchestrator to continue with the next step in a workflow.
:return: Result of playbook launch, this could either be successful or unsuccessful.
...
...
This diff is collapsed.
Click to expand it.
lso/routes/default.py
+
1
−
1
View file @
0dc1f3ce
...
...
@@ -8,7 +8,7 @@ from importlib import metadata
from
fastapi
import
APIRouter
from
pydantic
import
BaseModel
,
constr
API_VERSION
=
"
0.
1
"
API_VERSION
=
"
0.
2
"
VersionString
=
constr
(
pattern
=
r
"
\d+\.\d+
"
)
router
=
APIRouter
()
...
...
This diff is collapsed.
Click to expand it.
lso/routes/playbook.py
0 → 100644
+
46
−
0
View file @
0dc1f3ce
"""
The API endpoint from which Ansible playbooks can be executed.
"""
from
typing
import
Any
from
fastapi
import
APIRouter
from
pydantic
import
BaseModel
,
HttpUrl
from
lso.playbook
import
PlaybookLaunchResponse
,
get_playbook_path
,
run_playbook
router
=
APIRouter
()
class
PlaybookRunParams
(
BaseModel
):
"""
Parameters for executing an Ansible playbook.
"""
#: The filename of a playbook that is executed. It should be present inside the directory defined in the
#: configuration option ``ansible_playbooks_root_dir``.
playbook_name
:
str
#: The address where LSO should call back to upon completion.
callback
:
HttpUrl
#: The inventory to run the playbook against. This inventory can also include any host vars, if needed. When
#: including host vars, it should be a dictionary. Can be a simple string containing hostnames when no host vars are
#: needed. In the latter case, multiple hosts should be separated with a newline character.
inventory
:
dict
[
str
,
Any
]
|
str
#: Extra variables that should get passed to the playbook. This includes any required configuration objects
#: from the workflow orchestrator, commit comments, whether this execution should be a dry run, a trouble ticket
#: number, etc. Which extra vars are required solely depends on what inputs the playbook requires.
extra_vars
:
dict
@router.post
(
"
/
"
)
def
run_playbook_endpoint
(
params
:
PlaybookRunParams
)
->
PlaybookLaunchResponse
:
"""
Launch an Ansible playbook to modify or deploy a subscription instance.
The response will contain either a job ID, or error information.
:param params :class:`PlaybookRunParams`: Parameters for executing a playbook.
:return: Response from the Ansible runner, including a run ID.
:rtype: :class:`lso.playbook.PlaybookLaunchResponse`
"""
return
run_playbook
(
playbook_path
=
get_playbook_path
(
params
.
playbook_name
),
extra_vars
=
params
.
extra_vars
,
inventory
=
params
.
inventory
,
callback
=
params
.
callback
,
)
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