def chgroups(name, groups, append=True):
 if isinstance(groups, string_types):
  groups = groups.split(',')
 groups = [x.strip(' *') for x in groups]
 ugrps = set(list_groups(name))
 if (ugrps == set(groups)):
  return True
 name = _cmd_quote(name)
 if (not append):
  for group in ugrps:
   group = _cmd_quote(group).lstrip("'").rstrip("'")
   if (group not in groups):
    cmd = 'net localgroup "{0}" {1} /delete'.format(group, name)
    __salt__['cmd.run_all'](cmd, python_shell=True)
 for group in groups:
  if (group in ugrps):
   continue
  group = _cmd_quote(group).lstrip("'").rstrip("'")
  cmd = 'net localgroup "{0}" {1} /add'.format(group, name)
  out = __salt__['cmd.run_all'](cmd, python_shell=True)
  if (out['retcode'] != 0):
   log.error(out['stdout'])
   return False
 agrps = set(list_groups(name))
 return (len((ugrps - agrps)) == 0)

def chgroups ( name , groups , append = True ) : if isinstance ( groups , string_types ) : groups = groups . split ( ',' ) groups = [ x . strip ( ' *' ) for x in groups ] ugrps = set ( list_groups ( name ) ) if ( ugrps == set ( groups ) ) : return True name = _cmd_quote ( name ) if ( not append ) : for group in ugrps : group = _cmd_quote ( group ) . lstrip ( "'" ) . rstrip ( "'" ) if ( group not in groups ) : cmd = 'net localgroup "{0}" {1} /delete' . format ( group , name ) __salt__ [ 'cmd.run_all' ] ( cmd , python_shell = True ) for group in groups : if ( group in ugrps ) : continue group = _cmd_quote ( group ) . lstrip ( "'" ) . rstrip ( "'" ) cmd = 'net localgroup "{0}" {1} /add' . format ( group , name ) out = __salt__ [ 'cmd.run_all' ] ( cmd , python_shell = True ) if ( out [ 'retcode' ] != 0 ) : log . error ( out [ 'stdout' ] ) return False agrps = set ( list_groups ( name ) ) return ( len ( ( ugrps - agrps ) ) == 0 )
change the groups to which a user belongs name username to modify groups list of groups to set for the user .