def run_playbook(
    subscription_id,
    incident_id,
    resource_group,
    workspace_name,
    playbook_name,
    access_token,
):
    """
    Runs a playbook by name, resource group, and workspace name.
    Note: The return code is always 0. It cannot be relied upon to indicate
    success.
    """
    logic_apps_resource_id = (
        "/subscriptions/"
        + subscription_id
        + "/resourceGroups/"
        + resource_group
        + "/providers/Microsoft.Logic/workflows/"
        + playbook_name
    )
    result = subprocess.run(
        [
            "az",
            "sentinel",
            "incident",
            "run-playbook",
            "--incident-identifier",
            incident_id,
            "--resource-group",
            resource_group,
            "--workspace-name",
            workspace_name,
            "--logic-apps-resource-id",
            logic_apps_resource_id,
        ],
        stdout=subprocess.PIPE,
    )

    start_time = time.time()
    timeout = 5 * 60  # Timeout in seconds (5 minutes)

    while True:
        playbook_run = get_latest_playbook_run(
            access_token,
            subscription_id,
            resource_group,
            playbook_name,
        )
        if playbook_run["value"][0]["properties"]["status"] != "Running":
            break
        elapsed_time = time.time() - start_time
        if elapsed_time > timeout:
            print("Timeout reached: 5 minutes have passed.")
            break

        time.sleep(5)  # Sleep for 5 seconds between status checks


    run_status = playbook_run["value"][0]["properties"]["status"]
    assert run_status == "Succeeded", \
        f"Assertion failed. Status: {run_status} " \
        "Playbook Run:\n {json.dumps(playbook_run['value'][0], indent=2)}"
    return result.returncode

    Runs a playbook by name, resource group, and workspace name.
    Note: The return code is always 0. It cannot be relied upon to indicate
    success.
    
Solutions/CohesitySecurity/Tests/az.py