diff --git a/apps/accounts/automations/gather_accounts/manager.py b/apps/accounts/automations/gather_accounts/manager.py index f8949df4d..f0610e331 100644 --- a/apps/accounts/automations/gather_accounts/manager.py +++ b/apps/accounts/automations/gather_accounts/manager.py @@ -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) diff --git a/apps/assets/automations/base/manager.py b/apps/assets/automations/base/manager.py index 570f6f195..909ca5638 100644 --- a/apps/assets/automations/base/manager.py +++ b/apps/assets/automations/base/manager.py @@ -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)) diff --git a/apps/ops/ansible/callback.py b/apps/ops/ansible/callback.py index c11941be4..ce9713521 100644 --- a/apps/ops/ansible/callback.py +++ b/apps/ops/ansible/callback.py @@ -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):