def present(name, persist=False, mods=None):
    if not isinstance(mods, (list, tuple)):
        mods = [name]
    ret = {'name': name,
           'result': True,
           'changes': {},
           'comment': ''}

    loaded_mods = __salt__['kmod.mod_list']()
    if persist:
        persist_mods = __salt__['kmod.mod_list'](True)
        # Intersection of loaded modules and persistent modules
        loaded_mods = list(set(loaded_mods) & set(persist_mods))

    # Intersection of loaded and proposed modules
    already_loaded = list(set(loaded_mods) & set(mods))
    if len(already_loaded) == 1:
        comment = 'Kernel module {0} is already present'.format(already_loaded[0])
        _append_comment(ret, comment)
    elif len(already_loaded) > 1:
        comment = 'Kernel modules {0} are already present'.format(', '.join(already_loaded))
        _append_comment(ret, comment)

    if len(already_loaded) == len(mods):
        return ret  # all modules already loaded

    # Complement of proposed modules and already loaded modules
    not_loaded = list(set(mods) - set(already_loaded))

    if __opts__['test']:
        ret['result'] = None
        if len(ret['comment']):
            ret['comment'] += '\n'
        if len(not_loaded) == 1:
            comment = 'Kernel module {0} is set to be loaded'.format(not_loaded[0])
        else:
            comment = 'Kernel modules {0} are set to be loaded'.format(', '.join(not_loaded))
        _append_comment(ret, comment)
        return ret

    # Complement of proposed, unloaded modules and available modules
    unavailable = list(set(not_loaded) - set(__salt__['kmod.available']()))
    if unavailable:
        if len(unavailable) == 1:
            comment = 'Kernel module {0} is unavailable'.format(unavailable[0])
        else:
            comment = 'Kernel modules {0} are unavailable'.format(', '.join(unavailable))
        _append_comment(ret, comment)
        ret['result'] = False

    # The remaining modules are not loaded and are available for loading
    available = list(set(not_loaded) - set(unavailable))
    loaded = {'yes': [], 'no': [], 'failed': []}
    for mod in available:
        load_result = __salt__['kmod.load'](mod, persist)
        if isinstance(load_result, (list, tuple)):
            if len(load_result) > 0:
                for module in load_result:
                    ret['changes'][module] = 'loaded'
                loaded['yes'].append(mod)
            else:
                ret['result'] = False
                loaded['no'].append(mod)
        else:
            ret['result'] = False
            loaded['failed'].append([mod, load_result])

    # Update comment with results
    if len(loaded['yes']) == 1:
        _append_comment(ret, 'Loaded kernel module {0}'.format(loaded['yes'][0]))
    elif len(loaded['yes']) > 1:
        _append_comment(ret, 'Loaded kernel modules {0}'.format(', '.join(loaded['yes'])))

    if len(loaded['no']) == 1:
        _append_comment(ret, 'Failed to load kernel module {0}'.format(loaded['no'][0]))
    if len(loaded['no']) > 1:
        _append_comment(ret, 'Failed to load kernel modules {0}'.format(', '.join(loaded['no'])))

    if len(loaded['failed']):
        for mod, msg in loaded['failed']:
            _append_comment(ret, 'Failed to load kernel module {0}: {1}'.format(mod, msg))

    return ret
Ensure that the specified kernel module is loaded
dataset/ETHPy150Open saltstack/salt/salt/states/kmod.py/present