fix: windows gather account failed

pull/13218/head
feng 2024-05-13 18:00:17 +08:00 committed by Bryan
parent 77caa5536f
commit 0ea675f8d6
3 changed files with 17 additions and 5 deletions

View File

@ -51,8 +51,16 @@ class GatherAccountsManager(AccountBasePlaybookManager):
data = self.generate_data(asset, result)
self.asset_account_info[asset] = data
@staticmethod
def get_nested_info(data, *keys):
for key in keys:
data = data.get(key, {})
if not data:
break
return data
def on_host_success(self, host, result):
info = result.get('debug', {}).get('res', {}).get('info', {})
info = self.get_nested_info(result, 'debug', 'res', 'info')
asset = self.host_asset_mapper.get(host)
if asset and info:
result = self.filter_success_result(asset.type, info)

View File

@ -300,12 +300,16 @@ class BasePlaybookManager:
for host in hosts:
result = cb.host_results.get(host)
if state == 'ok':
self.on_host_success(host, result)
self.on_host_success(host, result.get('ok', ''))
elif state == 'skipped':
pass
else:
error = hosts.get(host)
self.on_host_error(host, error, result)
self.on_host_error(
host, error,
result.get('failures', '')
or result.get('dark', '')
)
def on_runner_failed(self, runner, e):
print("Runner failed: {} {}".format(e, self))

View File

@ -35,10 +35,10 @@ class DefaultCallback:
@property
def host_results(self):
results = {}
results = defaultdict(dict)
for state, hosts in self.result.items():
for host, items in hosts.items():
results[host] = items
results[host][state] = items
return results
def is_success(self):