Return the final state output.
    ret
        The initial state output structure.
    loaded
        The loaded dictionary.

def loaded_ret(ret, loaded, test, debug, compliance_report=False, opts=None):
    '''
    Return the final state output.
    ret
        The initial state output structure.
    loaded
        The loaded dictionary.
    '''
    # Always get the comment
    changes = {}
    ret['comment'] = loaded['comment']
    if 'diff' in loaded:
        changes['diff'] = loaded['diff']
    if 'commit_id' in loaded:
        changes['commit_id'] = loaded['commit_id']
    if 'compliance_report' in loaded:
        if compliance_report:
            changes['compliance_report'] = loaded['compliance_report']
    if debug and 'loaded_config' in loaded:
        changes['loaded_config'] = loaded['loaded_config']
    if changes.get('diff'):
        ret['comment'] = '{comment_base}\n\nConfiguration diff:\n\n{diff}'.format(comment_base=ret['comment'],
                                                                                  diff=changes['diff'])
    if changes.get('loaded_config'):
        ret['comment'] = '{comment_base}\n\nLoaded config:\n\n{loaded_cfg}'.format(
            comment_base=ret['comment'],
            loaded_cfg=changes['loaded_config'])
    if changes.get('compliance_report'):
        ret['comment'] = '{comment_base}\n\nCompliance report:\n\n{compliance}'.format(
            comment_base=ret['comment'],
            compliance=salt.output.string_format(changes['compliance_report'], 'nested', opts=opts))
    if not loaded.get('result', False):
        # Failure of some sort
        return ret
    if not loaded.get('already_configured', True):
        # We're making changes
        if test:
            ret['result'] = None
            return ret
        # Not test, changes were applied
        ret.update({
            'result': True,
            'changes': changes,
            'comment': "Configuration changed!\n{}".format(loaded['comment'])
        })
        return ret
    # No changes
    ret.update({
        'result': True,
        'changes': {}
    })
    return ret