def role_add(user, role):
 ret = {}
 roles = role.split(',')
 known_roles = role_list().keys()
 valid_roles = [r for r in roles if (r in known_roles)]
 log.debug('rbac.role_add - roles={0}, known_roles={1}, valid_roles={2}'.format(roles, known_roles, valid_roles))
 if (len(valid_roles) > 0):
  res = __salt__['cmd.run_all']('usermod -R "{roles}" {login}'.format(login=user, roles=','.join(set((role_get(user) + valid_roles)))))
  if (res['retcode'] > 0):
   ret['Error'] = {'retcode': res['retcode'], 'message': (res['stderr'] if ('stderr' in res) else res['stdout'])}
   return ret
 active_roles = role_get(user)
 for r in roles:
  if (r not in valid_roles):
   ret[r] = 'Unknown'
  elif (r in active_roles):
   ret[r] = 'Added'
  else:
   ret[r] = 'Failed'
 return ret

def role_add ( user , role ) : ret = { } roles = role . split ( ',' ) known_roles = role_list ( ) . keys ( ) valid_roles = [ r for r in roles if ( r in known_roles ) ] log . debug ( 'rbac.role_add - roles={0}, known_roles={1}, valid_roles={2}' . format ( roles , known_roles , valid_roles ) ) if ( len ( valid_roles ) > 0 ) : res = __salt__ [ 'cmd.run_all' ] ( 'usermod -R "{roles}" {login}' . format ( login = user , roles = ',' . join ( set ( ( role_get ( user ) + valid_roles ) ) ) ) ) if ( res [ 'retcode' ] > 0 ) : ret [ 'Error' ] = { 'retcode' : res [ 'retcode' ] , 'message' : ( res [ 'stderr' ] if ( 'stderr' in res ) else res [ 'stdout' ] ) } return ret active_roles = role_get ( user ) for r in roles : if ( r not in valid_roles ) : ret [ r ] = 'Unknown' elif ( r in active_roles ) : ret [ r ] = 'Added' else : ret [ r ] = 'Failed' return ret
add role to user user : string username role : string role name cli example: .