import yaml


def sort_roles(ansible_role_requirements_file):
    """ Separate the openstack roles from the external roles
    :param ansible_role_requirements_file: Path to the a-r-r file
    :returns: 3-tuple: (list of openstack roles, list of external roles, list of all roles)
    """
    with open(ansible_role_requirements_file, "r") as arryml:
        all_roles = yaml.safe_load(arryml)
    external_roles = []
    openstack_roles = []
    for role in all_roles:
        if role["src"].startswith("https://git.openstack.org/") or (
            role["src"].startswith("https://opendev.org/openstack/")
        ):
            openstack_roles.append(role)
        else:
            external_roles.append(role)
    return openstack_roles, external_roles, all_roles