<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def output(data, **kwargs):  # pylint: disable=unused-argument
    '''
    The HighState Outputter is only meant to be used with the state.highstate
    function, or a function that returns highstate return data.
    '''
    if len(data.keys()) == 1:
        # account for nested orchs via saltutil.runner
        if 'return' in data:
            data = data['return']

        # account for envelope data if being passed lookup_jid ret
        if isinstance(data, dict):
            _data = next(iter(data.values()))
            if 'jid' in _data and 'fun' in _data:
                data = _data['return']

    # output() is recursive, if we aren't passed a dict just return it
    if isinstance(data, int) or isinstance(data, six.string_types):
        return data

    # Discard retcode in dictionary as present in orchestrate data
    local_masters = [key for key in data.keys() if key.endswith('_master')]
    orchestrator_output = 'retcode' in data.keys() and len(local_masters) == 1

    if orchestrator_output:
        del data['retcode']

    # If additional information is passed through via the "data" dictionary to
    # the highstate outputter, such as "outputter" or "retcode", discard it.
    # We only want the state data that was passed through, if it is wrapped up
    # in the "data" key, as the orchestrate runner does. See Issue #31330,
    # pull request #27838, and pull request #27175 for more information.
    if 'data' in data:
        data = data.pop('data')

    indent_level = kwargs.get('indent_level', 1)
    ret = [
        _format_host(host, hostdata, indent_level=indent_level)[0]
        for host, hostdata in six.iteritems(data)
    ]
    if ret:
        return "\n".join(ret)
    log.error(
        'Data passed to highstate outputter is not a valid highstate return: %s',
        data
    )
    # We should not reach here, but if we do return empty string
    return ''