mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-07-16 08:54:41 +00:00
fix: support gateway tunnels in Docker-isolated Ansible tasks (#17021)
Co-authored-by: wangruidong <940853815@qq.com>
This commit is contained in:
@@ -59,12 +59,17 @@ class SSHTunnelManager:
|
||||
if not jms_gateway:
|
||||
continue
|
||||
try:
|
||||
gateway_proxy_host = interface.get_gateway_proxy_host()
|
||||
server = SSHTunnelForwarder(
|
||||
(jms_gateway["address"], jms_gateway["port"]),
|
||||
ssh_username=jms_gateway["username"],
|
||||
ssh_password=jms_gateway["secret"],
|
||||
ssh_pkey=jms_gateway["private_key_path"],
|
||||
remote_bind_address=(jms_asset["address"], jms_asset["port"]),
|
||||
local_bind_address=(
|
||||
'0.0.0.0' if gateway_proxy_host != '127.0.0.1' else '127.0.0.1',
|
||||
0,
|
||||
),
|
||||
)
|
||||
server.start()
|
||||
except Exception as e:
|
||||
@@ -75,7 +80,7 @@ class SSHTunnelManager:
|
||||
local_bind_port = server.local_bind_port
|
||||
|
||||
host["ansible_host"] = jms_asset["address"] = host["login_host"] = (
|
||||
interface.get_gateway_proxy_host()
|
||||
gateway_proxy_host
|
||||
)
|
||||
host["ansible_port"] = jms_asset["port"] = host["login_port"] = (
|
||||
local_bind_port
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
from socket import gethostbyname, gethostname
|
||||
|
||||
from django.utils.functional import LazyObject
|
||||
|
||||
from ops.ansible import AnsibleNativeRunner
|
||||
from ops.ansible.docker import use_ansible_docker_isolation
|
||||
from ops.ansible.runners.base import BaseRunner
|
||||
|
||||
__all__ = ['interface']
|
||||
@@ -28,6 +31,8 @@ class RunnerInterface:
|
||||
self._gateway_proxy_host = gateway_proxy_host
|
||||
|
||||
def get_gateway_proxy_host(self):
|
||||
if use_ansible_docker_isolation() and self._gateway_proxy_host == '127.0.0.1':
|
||||
return gethostbyname(gethostname())
|
||||
return self._gateway_proxy_host
|
||||
|
||||
def get_runner_type(self):
|
||||
|
||||
Reference in New Issue
Block a user