fix: 修复一些因使用 receptor runner 造成的 bug

pull/13029/head
Aaron3S 2024-04-15 19:29:22 +08:00 committed by Bryan
parent b8449a6efa
commit 44445a9482
21 changed files with 24 additions and 17 deletions

View File

@ -121,7 +121,7 @@ RUN set -ex \
COPY --from=stage-2 /opt/py3 /opt/py3
COPY --from=stage-1 /opt/jumpserver/release/jumpserver /opt/jumpserver
COPY --from=stage-1 /opt/jumpserver/release/jumpserver/apps/ops/ansible/ansible.cfg /etc/ansible/
COPY --from=stage-1 /opt/jumpserver/release/jumpserver/apps/libs/ansible/ansible.cfg /etc/ansible/
WORKDIR /opt/jumpserver

View File

@ -54,7 +54,7 @@ class SSHTunnelManager:
not_valid.append(k)
else:
local_bind_port = server.local_bind_port
host['ansible_host'] = jms_asset['address'] = host['login_host'] = '127.0.0.1'
host['ansible_host'] = jms_asset['address'] = host['login_host'] = 'jms_celery'
host['ansible_port'] = jms_asset['port'] = host['login_port'] = local_bind_port
servers.append(server)

View File

@ -12,8 +12,8 @@ class CeleryBaseService(BaseService):
@property
def cmd(self):
print('\n- Start Celery as Distributed Task Queue: {}'.format(self.queue.capitalize()))
ansible_config_path = os.path.join(settings.APPS_DIR, 'ops', 'ansible', 'ansible.cfg')
ansible_modules_path = os.path.join(settings.APPS_DIR, 'ops', 'ansible', 'modules')
ansible_config_path = os.path.join(settings.APPS_DIR, 'libs', 'ansible', 'ansible.cfg')
ansible_modules_path = os.path.join(settings.APPS_DIR, 'libs', 'ansible', 'modules')
os.environ.setdefault('LC_ALL', 'C.UTF-8')
os.environ.setdefault('PYTHONOPTIMIZE', '1')
os.environ.setdefault('ANSIBLE_FORCE_COLOR', 'True')

View File

@ -1,7 +1,7 @@
[defaults]
forks = 10
host_key_checking = False
library = /opt/jumpserver/apps/ops/ansible/modules:./modules
library = /opt/jumpserver/apps/libs/ansible/modules:./modules
timeout = 65
[inventory]
[privilege_escalation]

View File

View File

@ -63,7 +63,7 @@ name:
from ansible.module_utils.basic import AnsibleModule
from ops.ansible.modules_utils.custom_common import (
from libs.ansible.modules_utils.custom_common import (
SSHClient, common_argument_spec
)

View File

@ -91,7 +91,7 @@ users:
from ansible.module_utils.basic import AnsibleModule
from ops.ansible.modules_utils.oracle_common import (
from libs.ansible.modules_utils.oracle_common import (
OracleClient, oracle_common_argument_spec
)

View File

@ -46,7 +46,7 @@ conn_err_msg:
'''
from ansible.module_utils.basic import AnsibleModule
from ops.ansible.modules_utils.oracle_common import (
from libs.ansible.modules_utils.oracle_common import (
OracleClient, oracle_common_argument_spec
)

View File

@ -93,7 +93,7 @@ name:
from ansible.module_utils.basic import AnsibleModule
from ops.ansible.modules_utils.oracle_common import (
from libs.ansible.modules_utils.oracle_common import (
OracleClient, oracle_common_argument_spec
)

View File

@ -34,7 +34,7 @@ is_available:
from ansible.module_utils.basic import AnsibleModule
from ops.ansible.modules_utils.custom_common import (
from libs.ansible.modules_utils.custom_common import (
SSHClient, common_argument_spec
)

View File

@ -91,4 +91,3 @@ class OracleClient(object):
self._conn.close()
except:
pass

View File

@ -101,7 +101,7 @@ class PlaybookRunner:
entry = os.path.basename(self.playbook)
playbook_dir = os.path.dirname(self.playbook)
project_playbook_dir = os.path.join(self.project_dir, "project")
shutil.copytree(playbook_dir, project_playbook_dir)
shutil.copytree(playbook_dir, project_playbook_dir, dirs_exist_ok=True)
self.playbook = entry
def run(self, verbosity=0, **kwargs):

View File

@ -13,20 +13,26 @@ import psutil
from psutil import NoSuchProcess
ANSIBLE_RUNNER_COMMAND = "ansible-runner"
DEFAULT_SHARE_DIR = "data/share"
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
APPS_DIR = os.path.join(PROJECT_DIR, 'apps')
TEMP_DIR = os.path.join(PROJECT_DIR, "tmp")
DEFAULT_SHARE_DIR = os.path.join(PROJECT_DIR, "data", "share")
DEFAULT_ANSIBLE_MODULES_DIR = os.path.join(APPS_DIR, "libs", "ansible", "modules")
DEFAULT_CONTROL_SOCK_PATH = os.path.join(DEFAULT_SHARE_DIR, "control.sock")
logger = logging.getLogger(__name__)
os.chdir(APPS_DIR)
class ReceptorService:
def __init__(self):
self.pid_file = "tmp/receptor.pid"
self.pid_file = os.path.join(TEMP_DIR, "receptor.pid")
self.receptor_command = [
'receptor',
'--local-only',
'--log-level',
'level=Debug',
'--node', 'id=primary',
'--control-service',
'service=control',
@ -39,7 +45,7 @@ class ReceptorService:
'--work-command',
'worktype={}'.format("kill"),
'command={}'.format("python"),
"params=receptor kill",
"params={} kill".format(os.path.join(PROJECT_DIR, "receptor")),
'allowruntimeparams=true'
]
@ -67,6 +73,8 @@ class ReceptorService:
os.remove(self.pid_file)
os.environ.update({'LOCAL_CONNECTION_ENABLED': '1'})
os.environ.setdefault('ANSIBLE_LIBRARY', DEFAULT_ANSIBLE_MODULES_DIR)
os.environ.update({'PYTHONPATH': APPS_DIR})
process = subprocess.Popen(self.receptor_command)
with open(self.pid_file, 'w') as f:
f.write(str(process.pid))