diff --git a/jperm/ansible_api.py b/jperm/ansible_api.py index 20725908c..0b63b48f8 100644 --- a/jperm/ansible_api.py +++ b/jperm/ansible_api.py @@ -125,7 +125,7 @@ class MyRunner(MyInventory): self.results_raw = {} def run(self, module_name='shell', module_args='', timeout=10, forks=10, pattern='*', - become=False, become_method='sudo', become_user='root', become_pass='', transport='paramiko'): + become=False, become_method='sudo', become_user='root', become_pass='', transport='smart'): """ run module from andible ad-hoc. module_name: ansible module_name diff --git a/jperm/views.py b/jperm/views.py index d9d19da74..d7207b698 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals from django.db.models import Q from django.http import HttpResponseBadRequest, HttpResponseNotAllowed @@ -705,8 +706,14 @@ def perm_role_recycle(request): recycle_assets.append(asset) recycle_resource = gen_resource(recycle_assets) task = MyTask(recycle_resource) - # TODO: 判断返回结果,处理异常 - msg = task.del_user(get_object(PermRole, id=role_id).name) + try: + msg_del_user = task.del_user(get_object(PermRole, id=role_id).name) + msg_del_sudo = task.del_user_sudo(get_object(PermRole, id=role_id).name) + logger.info("recycle user msg: %s" % msg_del_user) + logger.info("recycle sudo msg: %s" % msg_del_sudo) + except Exception, e: + logger.warning("Recycle Role failed: %s" % e) + raise ServerError(u"回收已推送的系统用户失败: %s" % e) for asset_id in asset_ids: asset = get_object(Asset, id=asset_id)