def set_selinux_context(path, user=None, role=None, type=None, range=None):
 if (not any((user, role, type, range))):
  return False
 cmd = ['chcon']
 if user:
  cmd.extend(['-u', user])
 if role:
  cmd.extend(['-r', role])
 if type:
  cmd.extend(['-t', type])
 if range:
  cmd.extend(['-l', range])
 cmd.append(path)
 ret = (not __salt__['cmd.retcode'](cmd, python_shell=False))
 if ret:
  return get_selinux_context(path)
 else:
  return ret

def set_selinux_context ( path , user = None , role = None , type = None , range = None ) : if ( not any ( ( user , role , type , range ) ) ) : return False cmd = [ 'chcon' ] if user : cmd . extend ( [ '-u' , user ] ) if role : cmd . extend ( [ '-r' , role ] ) if type : cmd . extend ( [ '-t' , type ] ) if range : cmd . extend ( [ '-l' , range ] ) cmd . append ( path ) ret = ( not __salt__ [ 'cmd.retcode' ] ( cmd , python_shell = False ) ) if ret : return get_selinux_context ( path ) else : return ret
set a specific selinux label on a given path cli example: .