Execute the onlyif and unless logic.
    Return a result dict if:
    * onlyif failed (onlyif != 0)
    * unless succeeded (unless == 0)
    else return True

def mod_run_check(cmd_kwargs, onlyif, unless, creates):
    '''
    Execute the onlyif and unless logic.
    Return a result dict if:
    * onlyif failed (onlyif != 0)
    * unless succeeded (unless == 0)
    else return True
    '''
    # never use VT for onlyif/unless executions because this will lead
    # to quote problems
    cmd_kwargs = copy.deepcopy(cmd_kwargs)
    cmd_kwargs['use_vt'] = False
    cmd_kwargs['bg'] = False

    if onlyif is not None:
        if isinstance(onlyif, six.string_types):
            cmd = __salt__['cmd.retcode'](onlyif, ignore_retcode=True, python_shell=True, **cmd_kwargs)
            log.debug('Last command return code: %s', cmd)
            if cmd != 0:
                return {'comment': 'onlyif condition is false',
                        'skip_watch': True,
                        'result': True}
        elif isinstance(onlyif, list):
            for entry in onlyif:
                cmd = __salt__['cmd.retcode'](entry, ignore_retcode=True, python_shell=True, **cmd_kwargs)
                log.debug('Last command \'%s\' return code: %s', entry, cmd)
                if cmd != 0:
                    return {'comment': 'onlyif condition is false: {0}'.format(entry),
                            'skip_watch': True,
                            'result': True}
        elif not isinstance(onlyif, six.string_types):
            if not onlyif:
                log.debug('Command not run: onlyif did not evaluate to string_type')
                return {'comment': 'onlyif condition is false',
                        'skip_watch': True,
                        'result': True}

    if unless is not None:
        if isinstance(unless, six.string_types):
            cmd = __salt__['cmd.retcode'](unless, ignore_retcode=True, python_shell=True, **cmd_kwargs)
            log.debug('Last command return code: %s', cmd)
            if cmd == 0:
                return {'comment': 'unless condition is true',
                        'skip_watch': True,
                        'result': True}
        elif isinstance(unless, list):
            cmd = []
            for entry in unless:
                cmd.append(__salt__['cmd.retcode'](entry, ignore_retcode=True, python_shell=True, **cmd_kwargs))
                log.debug('Last command return code: %s', cmd)
            if all([c == 0 for c in cmd]):
                return {'comment': 'unless condition is true',
                        'skip_watch': True,
                        'result': True}
        elif not isinstance(unless, six.string_types):
            if unless:
                log.debug('Command not run: unless did not evaluate to string_type')
                return {'comment': 'unless condition is true',
                        'skip_watch': True,
                        'result': True}

    if isinstance(creates, six.string_types) and os.path.exists(creates):
        return {'comment': '{0} exists'.format(creates),
                'result': True}
    elif isinstance(creates, list) and all([
        os.path.exists(path) for path in creates
    ]):
        return {'comment': 'All files in creates exist',
                'result': True}

    # No reason to stop, return True
    return True