perf: 修改 inventory

pull/11148/head
ibuler 2023-08-01 10:39:34 +08:00 committed by Bryan
parent 8f59e49099
commit e015dd7bcb
2 changed files with 9 additions and 4 deletions

View File

@ -270,8 +270,13 @@ class JMSInventory:
name = host.pop('name')
name = name.replace('[', '_').replace(']', '_')
data['all']['hosts'][name] = host
if self.exclude_localhost and data['all']['hosts'].__contains__('localhost'):
data['all']['hosts'].update({'localhost': {'ansible_host': '255.255.255.255'}})
if not self.exclude_localhost:
data['all']['hosts'].update({
'localhost': {
'ansible_host': '127.0.0.1',
'ansible_connection': 'local'
}
})
return data
def write_to_file(self, path):

View File

@ -43,8 +43,8 @@ def get_parent_keys(key, include_self=True):
class JMSPermedInventory(JMSInventory):
def __init__(self, assets, account_policy='privileged_first',
account_prefer='root,Administrator', host_callback=None, exclude_localhost=False, user=None):
super().__init__(assets, account_policy, account_prefer, host_callback, exclude_localhost)
account_prefer='root,Administrator', host_callback=None, user=None):
super().__init__(assets, account_policy, account_prefer, host_callback, exclude_localhost=True)
self.user = user
self.assets_accounts_mapper = self.get_assets_accounts_mapper()