From 6a12bc39e9d07377ba1aaec227157b5a3cf7c06b Mon Sep 17 00:00:00 2001 From: Aaron3S Date: Thu, 11 Apr 2024 18:19:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ansible=20receptor=20=E9=80=82=E9=85=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/jumpserver/settings/base.py | 2 +- apps/ops/ansible/runner.py | 6 ++++-- apps/ops/api/job.py | 2 +- apps/ops/models/job.py | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/jumpserver/settings/base.py b/apps/jumpserver/settings/base.py index 6503b2477..0a21bd34f 100644 --- a/apps/jumpserver/settings/base.py +++ b/apps/jumpserver/settings/base.py @@ -38,6 +38,7 @@ BASE_DIR = const.BASE_DIR PROJECT_DIR = const.PROJECT_DIR APPS_DIR = os.path.join(PROJECT_DIR, 'apps') DATA_DIR = os.path.join(PROJECT_DIR, 'data') +SHARE_DIR = os.path.join(DATA_DIR, 'share') ANSIBLE_DIR = os.path.join(DATA_DIR, 'ansible') CERTS_DIR = os.path.join(DATA_DIR, 'certs') @@ -319,7 +320,6 @@ PRIVATE_STORAGE_AUTH_FUNCTION = 'jumpserver.rewriting.storage.permissions.allow_ PRIVATE_STORAGE_INTERNAL_URL = '/private-media/' PRIVATE_STORAGE_SERVER = 'jumpserver.rewriting.storage.servers.StaticFileServer' - # Use django-bootstrap-form to format template, input max width arg # BOOTSTRAP_COLUMN_COUNT = 11 diff --git a/apps/ops/ansible/runner.py b/apps/ops/ansible/runner.py index e468de3e2..b19e51618 100644 --- a/apps/ops/ansible/runner.py +++ b/apps/ops/ansible/runner.py @@ -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', diff --git a/apps/ops/api/job.py b/apps/ops/api/job.py index 55c342c00..98fded770 100644 --- a/apps/ops/api/job.py +++ b/apps/ops/api/job.py @@ -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}') diff --git a/apps/ops/models/job.py b/apps/ops/models/job.py index 6181ed1f0..759596d54 100644 --- a/apps/ops/models/job.py +++ b/apps/ops/models/job.py @@ -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