def profile_add(user, profile):
 ret = {}
 profiles = profile.split(',')
 known_profiles = profile_list().keys()
 valid_profiles = [p for p in profiles if (p in known_profiles)]
 log.debug('rbac.profile_add - profiles={0}, known_profiles={1}, valid_profiles={2}'.format(profiles, known_profiles, valid_profiles))
 if (len(valid_profiles) > 0):
  res = __salt__['cmd.run_all']('usermod -P "{profiles}" {login}'.format(login=user, profiles=','.join(set((profile_get(user) + valid_profiles)))))
  if (res['retcode'] > 0):
   ret['Error'] = {'retcode': res['retcode'], 'message': (res['stderr'] if ('stderr' in res) else res['stdout'])}
   return ret
 active_profiles = profile_get(user, False)
 for p in profiles:
  if (p not in valid_profiles):
   ret[p] = 'Unknown'
  elif (p in active_profiles):
   ret[p] = 'Added'
  else:
   ret[p] = 'Failed'
 return ret

def profile_add ( user , profile ) : ret = { } profiles = profile . split ( ',' ) known_profiles = profile_list ( ) . keys ( ) valid_profiles = [ p for p in profiles if ( p in known_profiles ) ] log . debug ( 'rbac.profile_add - profiles={0}, known_profiles={1}, valid_profiles={2}' . format ( profiles , known_profiles , valid_profiles ) ) if ( len ( valid_profiles ) > 0 ) : res = __salt__ [ 'cmd.run_all' ] ( 'usermod -P "{profiles}" {login}' . format ( login = user , profiles = ',' . join ( set ( ( profile_get ( user ) + valid_profiles ) ) ) ) ) if ( res [ 'retcode' ] > 0 ) : ret [ 'Error' ] = { 'retcode' : res [ 'retcode' ] , 'message' : ( res [ 'stderr' ] if ( 'stderr' in res ) else res [ 'stdout' ] ) } return ret active_profiles = profile_get ( user , False ) for p in profiles : if ( p not in valid_profiles ) : ret [ p ] = 'Unknown' elif ( p in active_profiles ) : ret [ p ] = 'Added' else : ret [ p ] = 'Failed' return ret
add profile to user user : string username profile : string profile name cli example: .