mirror of https://github.com/jumpserver/jumpserver
fix: ansible playbook render and run in localhost
parent
eb9f261459
commit
adbd73182b
|
@ -12,7 +12,7 @@ from sshtunnel import SSHTunnelForwarder
|
|||
|
||||
from assets.automations.methods import platform_automation_methods
|
||||
from common.utils import get_logger, lazyproperty, is_openssh_format_key, ssh_pubkey_gen
|
||||
from ops.ansible import JMSInventory, PlaybookRunner, DefaultCallback
|
||||
from ops.ansible import JMSInventory, SuperPlaybookRunner, DefaultCallback
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
@ -269,7 +269,7 @@ class BasePlaybookManager:
|
|||
if not playbook_path:
|
||||
continue
|
||||
|
||||
runer = PlaybookRunner(
|
||||
runer = SuperPlaybookRunner(
|
||||
inventory_path,
|
||||
playbook_path,
|
||||
self.runtime_dir,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import uuid
|
||||
import shutil
|
||||
import uuid
|
||||
|
||||
import ansible_runner
|
||||
from django.conf import settings
|
||||
from django.utils._os import safe_join
|
||||
|
@ -43,6 +44,9 @@ class AdHocRunner:
|
|||
|
||||
if not os.path.exists(self.project_dir):
|
||||
os.mkdir(self.project_dir, 0o755)
|
||||
private_env = safe_join(self.project_dir, 'env')
|
||||
if os.path.exists(private_env):
|
||||
shutil.rmtree(private_env)
|
||||
|
||||
ansible_runner.run(
|
||||
timeout=self.timeout if self.timeout > 0 else None,
|
||||
|
@ -69,9 +73,13 @@ class PlaybookRunner:
|
|||
if not callback:
|
||||
callback = DefaultCallback()
|
||||
self.cb = callback
|
||||
self.envs = {}
|
||||
|
||||
def run(self, verbosity=0, **kwargs):
|
||||
verbosity = get_ansible_log_verbosity(verbosity)
|
||||
private_env = safe_join(self.project_dir, 'env')
|
||||
if os.path.exists(private_env):
|
||||
shutil.rmtree(private_env)
|
||||
|
||||
ansible_runner.run(
|
||||
private_data_dir=self.project_dir,
|
||||
|
@ -81,11 +89,18 @@ class PlaybookRunner:
|
|||
event_handler=self.cb.event_handler,
|
||||
status_handler=self.cb.status_handler,
|
||||
host_cwd=self.project_dir,
|
||||
envvars=self.envs,
|
||||
**kwargs
|
||||
)
|
||||
return self.cb
|
||||
|
||||
|
||||
class SuperPlaybookRunner(PlaybookRunner):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.envs = {"LOCAL_CONNECTION_ENABLED": "1"}
|
||||
|
||||
|
||||
class UploadFileRunner:
|
||||
def __init__(self, inventory, job_id, dest_path, callback=None):
|
||||
self.id = uuid.uuid4()
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.utils import timezone
|
|||
|
||||
from common.db.utils import safe_db_connection
|
||||
from common.utils import get_logger, random_string
|
||||
from ops.ansible import PlaybookRunner, JMSInventory
|
||||
from ops.ansible import SuperPlaybookRunner, JMSInventory
|
||||
from terminal.models import Applet, AppletHostDeployment
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
@ -114,7 +114,7 @@ class DeployAppletHostManager:
|
|||
def _run_playbook(self, generate_playbook: callable, **kwargs):
|
||||
inventory = self.generate_inventory()
|
||||
playbook = generate_playbook()
|
||||
runner = PlaybookRunner(
|
||||
runner = SuperPlaybookRunner(
|
||||
inventory=inventory, playbook=playbook, project_dir=self.run_dir
|
||||
)
|
||||
return runner.run(**kwargs)
|
||||
|
|
|
@ -11,7 +11,7 @@ python = "^3.11"
|
|||
cython = "3.0.0"
|
||||
aiofiles = "23.1.0"
|
||||
amqp = "5.1.1"
|
||||
ansible-core = { url = "https://github.com/jumpserver/ansible/releases/download/v2.14.1.2/ansible-2.14.1.2.zip" }
|
||||
ansible-core = { url = "https://github.com/jumpserver/ansible/archive/refs/tags/v2.14.1.4.zip" }
|
||||
ansible = "7.1.0"
|
||||
ansible-runner = "2.3.3"
|
||||
asn1crypto = "1.5.1"
|
||||
|
|
Loading…
Reference in New Issue