mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-26 23:34:26 +00:00
feat: ansible receptor 适配文件上传
This commit is contained in:
@@ -133,17 +133,19 @@ class SuperPlaybookRunner(PlaybookRunner):
|
||||
|
||||
|
||||
class UploadFileRunner:
|
||||
def __init__(self, inventory, job_id, dest_path, callback=None):
|
||||
def __init__(self, inventory, project_dir, job_id, dest_path, callback=None):
|
||||
self.id = uuid.uuid4()
|
||||
self.inventory = inventory
|
||||
self.project_dir = project_dir
|
||||
self.cb = DefaultCallback()
|
||||
upload_file_dir = safe_join(settings.DATA_DIR, 'job_upload_file')
|
||||
upload_file_dir = safe_join(settings.SHARE_DIR, 'job_upload_file')
|
||||
self.src_paths = safe_join(upload_file_dir, str(job_id))
|
||||
self.dest_path = safe_join("/tmp", dest_path)
|
||||
|
||||
def run(self, verbosity=0, **kwargs):
|
||||
verbosity = get_ansible_log_verbosity(verbosity)
|
||||
runner.run(
|
||||
private_data_dir=self.project_dir,
|
||||
host_pattern="*",
|
||||
inventory=self.inventory,
|
||||
module='copy',
|
||||
|
@@ -178,7 +178,7 @@ class JobViewSet(OrgBulkModelViewSet):
|
||||
job = get_object_or_404(Job, pk=job_id, creator=request.user)
|
||||
job_args = json.loads(job.args)
|
||||
src_path_info = []
|
||||
upload_file_dir = safe_join(settings.DATA_DIR, 'job_upload_file', job_id)
|
||||
upload_file_dir = safe_join(settings.SHARE_DIR, 'job_upload_file', job_id)
|
||||
for uploaded_file in uploaded_files:
|
||||
filename = uploaded_file.name
|
||||
saved_path = safe_join(upload_file_dir, f'{filename}')
|
||||
|
@@ -58,7 +58,7 @@ class JMSPermedInventory(JMSInventory):
|
||||
self.module = module
|
||||
self.assets_accounts_mapper = self.get_assets_accounts_mapper()
|
||||
|
||||
def make_account_vars(self, host, asset, account, automation, protocol, platform, gateway):
|
||||
def make_account_vars(self, host, asset, account, automation, protocol, platform, gateway, path_dir):
|
||||
if not account:
|
||||
host['error'] = _("No account available")
|
||||
return host
|
||||
@@ -90,7 +90,7 @@ class JMSPermedInventory(JMSInventory):
|
||||
}
|
||||
host['jms_asset']['port'] = protocol.port
|
||||
return host
|
||||
return super().make_account_vars(host, asset, account, automation, protocol, platform, gateway)
|
||||
return super().make_account_vars(host, asset, account, automation, protocol, platform, gateway, path_dir)
|
||||
|
||||
def get_asset_sorted_accounts(self, asset):
|
||||
accounts = self.assets_accounts_mapper.get(asset.id, [])
|
||||
@@ -347,7 +347,7 @@ class JobExecution(JMSOrgBaseModel):
|
||||
job_id = self.current_job.id
|
||||
args = json.loads(self.current_job.args)
|
||||
dst_path = args.get('dst_path', '/')
|
||||
runner = UploadFileRunner(self.inventory_path, job_id, dst_path)
|
||||
runner = UploadFileRunner(self.inventory_path, self.private_dir, job_id, dst_path)
|
||||
else:
|
||||
raise Exception("unsupported job type")
|
||||
return runner
|
||||
|
Reference in New Issue
Block a user