Only succeed if the value in the given register location contains
    the given value

    USAGE:

    .. code-block:: yaml

        foo:
          check.contains:
            - value: itni

        run_remote_ex:
          local.cmd:
            - tgt: '*'
            - func: test.ping
            - require:
              - check: foo

def contains(name,
             value,
             count_lt=None,
             count_lte=None,
             count_eq=None,
             count_gte=None,
             count_gt=None,
             count_ne=None):
    '''
    Only succeed if the value in the given register location contains
    the given value

    USAGE:

    .. code-block:: yaml

        foo:
          check.contains:
            - value: itni

        run_remote_ex:
          local.cmd:
            - tgt: '*'
            - func: test.ping
            - require:
              - check: foo
    '''
    ret = {'name': name,
           'result': False,
           'comment': '',
           'changes': {}}
    if name not in __reg__:
        ret['result'] = False
        ret['comment'] = 'Value {0} not in register'.format(name)
        return ret
    try:
        count_compare = count_lt or count_lte or count_eq or\
                        count_gte or count_gt or count_ne
        if count_compare:
            occurrences = __reg__[name]['val'].count(value)
            log.debug('%s appears %s times', value, occurrences)
            ret['result'] = True
            if count_lt:
                ret['result'] &= occurrences < count_lt
            if count_lte:
                ret['result'] &= occurrences <= count_lte
            if count_eq:
                ret['result'] &= occurrences == count_eq
            if count_gte:
                ret['result'] &= occurrences >= count_gte
            if count_gt:
                ret['result'] &= occurrences > count_gt
            if count_ne:
                ret['result'] &= occurrences != count_ne
        else:
            if value in __reg__[name]['val']:
                ret['result'] = True
    except TypeError:
        pass
    return ret