Skip to content
Snippets Groups Projects
Verified Commit 8667a603 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

add checks to playbook to see file exists and inventory is valid

parent 0dc1f3ce
No related branches found
No related tags found
No related merge requests found
...@@ -143,7 +143,7 @@ def _run_playbook_proc( ...@@ -143,7 +143,7 @@ def _run_playbook_proc(
job_id: str, job_id: str,
playbook_path: str, playbook_path: str,
extra_vars: dict, extra_vars: dict,
inventory: list[str], inventory: dict[str, Any] | str,
callback: str, callback: str,
) -> None: ) -> None:
"""Run a playbook, internal function. """Run a playbook, internal function.
...@@ -152,7 +152,7 @@ def _run_playbook_proc( ...@@ -152,7 +152,7 @@ def _run_playbook_proc(
:param str playbook_path: Ansible playbook to be executed. :param str playbook_path: Ansible playbook to be executed.
:param dict extra_vars: Extra variables passed to the Ansible playbook. :param dict extra_vars: Extra variables passed to the Ansible playbook.
: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 dict[str, Any] | str inventory: Ansible inventory to run the playbook against.
""" """
ansible_playbook_run = ansible_runner.run( ansible_playbook_run = ansible_runner.run(
playbook=playbook_path, playbook=playbook_path,
...@@ -192,6 +192,14 @@ def run_playbook( ...@@ -192,6 +192,14 @@ def run_playbook(
:return: Result of playbook launch, this could either be successful or unsuccessful. :return: Result of playbook launch, this could either be successful or unsuccessful.
:rtype: :class:`PlaybookLaunchResponse` :rtype: :class:`PlaybookLaunchResponse`
""" """
if not Path.exists(playbook_path):
msg = f"Filename '{playbook_path}' does not exist."
return playbook_launch_error(msg)
if not ansible_runner.utils.isinventory(inventory):
msg = "Invalid inventory provided. Should be a string, or JSON object."
return playbook_launch_error(msg)
job_id = str(uuid.uuid4()) job_id = str(uuid.uuid4())
thread = threading.Thread( thread = threading.Thread(
target=_run_playbook_proc, target=_run_playbook_proc,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment