Browse Source

[Bugfix] 修复动态系统用户执行批量命令的bug

pull/3782/head
ibuler 5 years ago
parent
commit
00b3c7c945
  1. 4
      apps/ops/inventory.py
  2. 7
      apps/ops/models/command.py

4
apps/ops/inventory.py

@ -92,7 +92,7 @@ class JMSInventory(JMSBaseInventory):
for asset in assets:
host = self.convert_to_ansible(asset, run_as_admin=run_as_admin)
if run_as:
if run_as is not None:
run_user_info = self.get_run_user_info(host)
host.update(run_user_info)
if become_info and asset.is_unixlike():
@ -104,7 +104,7 @@ class JMSInventory(JMSBaseInventory):
def get_run_user_info(self, host):
from assets.backends import AssetUserManager
if not self.run_as:
if self.run_as is None:
return {}
try:

7
apps/ops/models/command.py

@ -33,7 +33,12 @@ class CommandExecution(OrgModelMixin):
@property
def inventory(self):
return JMSInventory(self.hosts.all(), run_as=self.run_as.username)
if self.run_as.username_same_with_user:
username = self.user.username
else:
username = self.run_as.username
inv = JMSInventory(self.hosts.all(), run_as=username)
return inv
@property
def result(self):

Loading…
Cancel
Save