diff --git a/changelogs/fragments/always_keep_subset.yml b/changelogs/fragments/always_keep_subset.yml new file mode 100644 index 00000000000..db5ef8c2db6 --- /dev/null +++ b/changelogs/fragments/always_keep_subset.yml @@ -0,0 +1,2 @@ +bugfixes: + - keep results subset also when not no_log. diff --git a/lib/ansible/executor/task_result.py b/lib/ansible/executor/task_result.py index 3a8dd0c7a01..c3f1a7ce348 100644 --- a/lib/ansible/executor/task_result.py +++ b/lib/ansible/executor/task_result.py @@ -119,6 +119,15 @@ class TaskResult: else: ignore = _IGNORE + subset = {} + # preserve subset for later + for sub in _SUB_PRESERVE: + if sub in self._result: + subset[sub] = {} + for key in _SUB_PRESERVE[sub]: + if key in self._result[sub]: + subset[sub][key] = self._result[sub][key] + if isinstance(self._task.no_log, bool) and self._task.no_log or self._result.get('_ansible_no_log', False): x = {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result"} @@ -127,14 +136,6 @@ class TaskResult: if preserve in self._result: x[preserve] = self._result[preserve] - # preserve subset - for sub in _SUB_PRESERVE: - if sub in self._result: - x[sub] = {} - for key in _SUB_PRESERVE[sub]: - if key in self._result[sub]: - x[sub][key] = self._result[sub][key] - result._result = x elif self._result: result._result = module_response_deepcopy(self._result) @@ -147,4 +148,7 @@ class TaskResult: # remove almost ALL internal keys, keep ones relevant to callback strip_internal_keys(result._result, exceptions=CLEAN_EXCEPTIONS) + # keep subset + result._result.update(subset) + return result