def mod_run_check(cmd_kwargs, onlyif, unless, creates):
 cmd_kwargs = copy.deepcopy(cmd_kwargs)
 cmd_kwargs['use_vt'] = False
 if (onlyif is not None):
  if isinstance(onlyif, string_types):
   cmd = __salt__['cmd.retcode'](onlyif, ignore_retcode=True, python_shell=True, **cmd_kwargs)
   log.debug('Last command return code: {0}'.format(cmd))
   if (cmd != 0):
    return {'comment': 'onlyif execution failed', '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 '{0}' return code: {1}".format(entry, cmd))
    if (cmd != 0):
     return {'comment': 'onlyif execution failed: {0}'.format(entry), 'skip_watch': True, 'result': True}
  elif (not isinstance(onlyif, string_types)):
   if (not onlyif):
    log.debug('Command not run: onlyif did not evaluate to string_type')
    return {'comment': 'onlyif execution failed', 'skip_watch': True, 'result': True}
 if (unless is not None):
  if isinstance(unless, string_types):
   cmd = __salt__['cmd.retcode'](unless, ignore_retcode=True, python_shell=True, **cmd_kwargs)
   log.debug('Last command return code: {0}'.format(cmd))
   if (cmd == 0):
    return {'comment': 'unless execution succeeded', '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: {0}'.format(cmd))
   if all([(c == 0) for c in cmd]):
    return {'comment': 'unless execution succeeded', 'skip_watch': True, 'result': True}
  elif (not isinstance(unless, string_types)):
   if unless:
    log.debug('Command not run: unless did not evaluate to string_type')
    return {'comment': 'unless execution succeeded', 'skip_watch': True, 'result': True}
 if (isinstance(creates, 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}
 return True

def mod_run_check ( cmd_kwargs , onlyif , unless , creates ) : cmd_kwargs = copy . deepcopy ( cmd_kwargs ) cmd_kwargs [ 'use_vt' ] = False if ( onlyif is not None ) : if isinstance ( onlyif , string_types ) : cmd = __salt__ [ 'cmd.retcode' ] ( onlyif , ignore_retcode = True , python_shell = True , ** cmd_kwargs ) log . debug ( 'Last command return code: {0}' . format ( cmd ) ) if ( cmd != 0 ) : return { 'comment' : 'onlyif execution failed' , '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 '{0}' return code: {1}" . format ( entry , cmd ) ) if ( cmd != 0 ) : return { 'comment' : 'onlyif execution failed: {0}' . format ( entry ) , 'skip_watch' : True , 'result' : True } elif ( not isinstance ( onlyif , string_types ) ) : if ( not onlyif ) : log . debug ( 'Command not run: onlyif did not evaluate to string_type' ) return { 'comment' : 'onlyif execution failed' , 'skip_watch' : True , 'result' : True } if ( unless is not None ) : if isinstance ( unless , string_types ) : cmd = __salt__ [ 'cmd.retcode' ] ( unless , ignore_retcode = True , python_shell = True , ** cmd_kwargs ) log . debug ( 'Last command return code: {0}' . format ( cmd ) ) if ( cmd == 0 ) : return { 'comment' : 'unless execution succeeded' , '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: {0}' . format ( cmd ) ) if all ( [ ( c == 0 ) for c in cmd ] ) : return { 'comment' : 'unless execution succeeded' , 'skip_watch' : True , 'result' : True } elif ( not isinstance ( unless , string_types ) ) : if unless : log . debug ( 'Command not run: unless did not evaluate to string_type' ) return { 'comment' : 'unless execution succeeded' , 'skip_watch' : True , 'result' : True } if ( isinstance ( creates , 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 } return True
execute the onlyif and unless logic .