perf: Ansible inventory set jms

pull/13434/head^2
feng 2024-06-14 16:49:32 +08:00 committed by Bryan
parent 887724bad4
commit 9be77cf58f
4 changed files with 22 additions and 23 deletions

View File

@ -13,11 +13,11 @@
login_password: "{{ jms_account.secret }}" login_password: "{{ jms_account.secret }}"
login_secret_type: "{{ jms_account.secret_type }}" login_secret_type: "{{ jms_account.secret_type }}"
login_private_key_path: "{{ jms_account.private_key_path }}" login_private_key_path: "{{ jms_account.private_key_path }}"
become: "{{ custom_become | default(False) }}" become: "{{ jms_custom_become | default(False) }}"
become_method: "{{ custom_become_method | default('su') }}" become_method: "{{ jms_custom_become_method | default('su') }}"
become_user: "{{ custom_become_user | default('') }}" become_user: "{{ jms_custom_become_user | default('') }}"
become_password: "{{ custom_become_password | default('') }}" become_password: "{{ jms_custom_become_password | default('') }}"
become_private_key_path: "{{ custom_become_private_key_path | default(None) }}" become_private_key_path: "{{ jms_custom_become_private_key_path | default(None) }}"
old_ssh_version: "{{ jms_asset.old_ssh_version | default(False) }}" old_ssh_version: "{{ jms_asset.old_ssh_version | default(False) }}"
gateway_args: "{{ jms_asset.ansible_ssh_common_args | default(None) }}" gateway_args: "{{ jms_asset.ansible_ssh_common_args | default(None) }}"
register: ping_info register: ping_info
@ -31,11 +31,11 @@
login_port: "{{ jms_asset.port }}" login_port: "{{ jms_asset.port }}"
login_secret_type: "{{ jms_account.secret_type }}" login_secret_type: "{{ jms_account.secret_type }}"
login_private_key_path: "{{ jms_account.private_key_path }}" login_private_key_path: "{{ jms_account.private_key_path }}"
become: "{{ custom_become | default(False) }}" become: "{{ jms_custom_become | default(False) }}"
become_method: "{{ custom_become_method | default('su') }}" become_method: "{{ jms_custom_become_method | default('su') }}"
become_user: "{{ custom_become_user | default('') }}" become_user: "{{ jms_custom_become_user | default('') }}"
become_password: "{{ custom_become_password | default('') }}" become_password: "{{ jms_custom_become_password | default('') }}"
become_private_key_path: "{{ custom_become_private_key_path | default(None) }}" become_private_key_path: "{{ jms_custom_become_private_key_path | default(None) }}"
name: "{{ account.username }}" name: "{{ account.username }}"
password: "{{ account.secret }}" password: "{{ account.secret }}"
commands: "{{ params.commands }}" commands: "{{ params.commands }}"

View File

@ -37,7 +37,7 @@ class SSHTunnelManager:
info = self.file_to_json(runner.inventory) info = self.file_to_json(runner.inventory)
servers, not_valid = [], [] servers, not_valid = [], []
for k, host in info['all']['hosts'].items(): for k, host in info['all']['hosts'].items():
jms_asset, jms_gateway = host.get('jms_asset'), host.get('gateway') jms_asset, jms_gateway = host.get('jms_asset'), host.get('jms_gateway')
if not jms_gateway: if not jms_gateway:
continue continue
try: try:

View File

@ -14,11 +14,11 @@
login_port: "{{ jms_asset.port }}" login_port: "{{ jms_asset.port }}"
login_secret_type: "{{ jms_account.secret_type }}" login_secret_type: "{{ jms_account.secret_type }}"
login_private_key_path: "{{ jms_account.private_key_path }}" login_private_key_path: "{{ jms_account.private_key_path }}"
become: "{{ custom_become | default(False) }}" become: "{{ jms_custom_become | default(False) }}"
become_method: "{{ custom_become_method | default('su') }}" become_method: "{{ jms_custom_become_method | default('su') }}"
become_user: "{{ custom_become_user | default('') }}" become_user: "{{ jms_custom_become_user | default('') }}"
become_password: "{{ custom_become_password | default('') }}" become_password: "{{ jms_custom_become_password | default('') }}"
become_private_key_path: "{{ custom_become_private_key_path | default(None) }}" become_private_key_path: "{{ jms_custom_become_private_key_path | default(None) }}"
old_ssh_version: "{{ jms_asset.old_ssh_version | default(False) }}" old_ssh_version: "{{ jms_asset.old_ssh_version | default(False) }}"
gateway_args: "{{ jms_asset.ansible_ssh_common_args | default(None) }}" gateway_args: "{{ jms_asset.ansible_ssh_common_args | default(None) }}"

View File

@ -5,7 +5,6 @@ import re
from collections import defaultdict from collections import defaultdict
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from assets.const.category import Category
__all__ = ['JMSInventory'] __all__ = ['JMSInventory']
@ -84,11 +83,11 @@ class JMSInventory:
def make_custom_become_ansible_vars(account, su_from_auth, path_dir): def make_custom_become_ansible_vars(account, su_from_auth, path_dir):
su_method = su_from_auth['ansible_become_method'] su_method = su_from_auth['ansible_become_method']
var = { var = {
'custom_become': True, 'jms_custom_become': True,
'custom_become_method': su_method, 'jms_custom_become_method': su_method,
'custom_become_user': account.su_from.username, 'jms_custom_become_user': account.su_from.username,
'custom_become_password': account.escape_jinja2_syntax(account.su_from.secret), 'jms_custom_become_password': account.escape_jinja2_syntax(account.su_from.secret),
'custom_become_private_key_path': account.su_from.get_private_key_path(path_dir) 'jms_custom_become_private_key_path': account.su_from.get_private_key_path(path_dir)
} }
return var return var
@ -132,7 +131,7 @@ class JMSInventory:
if gateway: if gateway:
ansible_connection = host.get('ansible_connection', 'ssh') ansible_connection = host.get('ansible_connection', 'ssh')
if ansible_connection in ('local', 'winrm', 'rdp'): if ansible_connection in ('local', 'winrm', 'rdp'):
host['gateway'] = { host['jms_gateway'] = {
'address': gateway.address, 'port': gateway.port, 'address': gateway.address, 'port': gateway.port,
'username': gateway.username, 'secret': gateway.password, 'username': gateway.username, 'secret': gateway.password,
'private_key_path': gateway.get_private_key_path(path_dir) 'private_key_path': gateway.get_private_key_path(path_dir)