mirror of https://github.com/jumpserver/jumpserver
fix: 修复执行快捷命令时 local_connection 没有被正确设置
parent
2acc84dc69
commit
9b20b67039
|
@ -14,8 +14,10 @@ __all__ = ['AdHocRunner', 'PlaybookRunner', 'SuperPlaybookRunner', 'UploadFileRu
|
||||||
|
|
||||||
class AdHocRunner:
|
class AdHocRunner:
|
||||||
cmd_modules_choices = ('shell', 'raw', 'command', 'script', 'win_shell')
|
cmd_modules_choices = ('shell', 'raw', 'command', 'script', 'win_shell')
|
||||||
|
need_local_connection_modules_choices = ("mysql", "postgresql", "sqlserver", "huawei")
|
||||||
|
|
||||||
def __init__(self, inventory, module, module_args='', pattern='*', project_dir='/tmp/', extra_vars=None,
|
def __init__(self, inventory, job_module, module, module_args='', pattern='*', project_dir='/tmp/',
|
||||||
|
extra_vars=None,
|
||||||
dry_run=False, timeout=-1):
|
dry_run=False, timeout=-1):
|
||||||
if extra_vars is None:
|
if extra_vars is None:
|
||||||
extra_vars = {}
|
extra_vars = {}
|
||||||
|
@ -23,6 +25,7 @@ class AdHocRunner:
|
||||||
self.inventory = inventory
|
self.inventory = inventory
|
||||||
self.pattern = pattern
|
self.pattern = pattern
|
||||||
self.module = module
|
self.module = module
|
||||||
|
self.job_module = job_module
|
||||||
self.module_args = module_args
|
self.module_args = module_args
|
||||||
self.project_dir = project_dir
|
self.project_dir = project_dir
|
||||||
self.cb = DefaultCallback()
|
self.cb = DefaultCallback()
|
||||||
|
@ -30,8 +33,7 @@ class AdHocRunner:
|
||||||
self.extra_vars = extra_vars
|
self.extra_vars = extra_vars
|
||||||
self.dry_run = dry_run
|
self.dry_run = dry_run
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
# enable local connection
|
self.envs = {}
|
||||||
self.extra_vars.update({"LOCAL_CONNECTION_ENABLED": "1"})
|
|
||||||
|
|
||||||
def check_module(self):
|
def check_module(self):
|
||||||
if self.module not in self.cmd_modules_choices:
|
if self.module not in self.cmd_modules_choices:
|
||||||
|
@ -40,8 +42,13 @@ class AdHocRunner:
|
||||||
raise CommandInBlackListException(
|
raise CommandInBlackListException(
|
||||||
"Command is rejected by black list: {}".format(self.module_args.split()[0]))
|
"Command is rejected by black list: {}".format(self.module_args.split()[0]))
|
||||||
|
|
||||||
|
def set_local_connection(self):
|
||||||
|
if self.job_module in self.need_local_connection_modules_choices:
|
||||||
|
self.envs.update({"LOCAL_CONNECTION_ENABLED": "1"})
|
||||||
|
|
||||||
def run(self, verbosity=0, **kwargs):
|
def run(self, verbosity=0, **kwargs):
|
||||||
self.check_module()
|
self.check_module()
|
||||||
|
self.set_local_connection()
|
||||||
verbosity = get_ansible_log_verbosity(verbosity)
|
verbosity = get_ansible_log_verbosity(verbosity)
|
||||||
|
|
||||||
if not os.path.exists(self.project_dir):
|
if not os.path.exists(self.project_dir):
|
||||||
|
@ -53,6 +60,7 @@ class AdHocRunner:
|
||||||
interface.run(
|
interface.run(
|
||||||
timeout=self.timeout if self.timeout > 0 else None,
|
timeout=self.timeout if self.timeout > 0 else None,
|
||||||
extravars=self.extra_vars,
|
extravars=self.extra_vars,
|
||||||
|
envvars=self.envs,
|
||||||
host_pattern=self.pattern,
|
host_pattern=self.pattern,
|
||||||
private_data_dir=self.project_dir,
|
private_data_dir=self.project_dir,
|
||||||
inventory=self.inventory,
|
inventory=self.inventory,
|
||||||
|
|
|
@ -334,6 +334,7 @@ class JobExecution(JMSOrgBaseModel):
|
||||||
|
|
||||||
runner = AdHocRunner(
|
runner = AdHocRunner(
|
||||||
self.inventory_path,
|
self.inventory_path,
|
||||||
|
self.job.module,
|
||||||
module,
|
module,
|
||||||
timeout=self.current_job.timeout,
|
timeout=self.current_job.timeout,
|
||||||
module_args=args,
|
module_args=args,
|
||||||
|
|
1
receptor
1
receptor
|
@ -75,7 +75,6 @@ class ReceptorService:
|
||||||
print("\n- PID file is corrupted, starting Receptor...")
|
print("\n- PID file is corrupted, starting Receptor...")
|
||||||
os.remove(self.pid_file)
|
os.remove(self.pid_file)
|
||||||
|
|
||||||
os.environ.update({'LOCAL_CONNECTION_ENABLED': '1'})
|
|
||||||
os.environ.setdefault('ANSIBLE_LIBRARY', DEFAULT_ANSIBLE_MODULES_DIR)
|
os.environ.setdefault('ANSIBLE_LIBRARY', DEFAULT_ANSIBLE_MODULES_DIR)
|
||||||
os.environ.update({'PYTHONPATH': APPS_DIR})
|
os.environ.update({'PYTHONPATH': APPS_DIR})
|
||||||
process = subprocess.Popen(self.receptor_command)
|
process = subprocess.Popen(self.receptor_command)
|
||||||
|
|
Loading…
Reference in New Issue