zuul_json: remove no_log handling

The current no_log handling here was added in the following steps

Ic1becaf2f3ab345da22fa62314f1296d76777fec was the original zuul_json
and added the check of the result object

  if result._result.get('_ansible_no_log', False):

This happened in July, 2017.  However, soon after in October 2017,
Ansible merged [1] which changed things so that the callbacks
(v2_runner_on_ok) get "clean copy" of the TaskResult object; e.g.

   if isinstance(arg, TaskResult):
       new_args.append(arg.clean_copy())

It can be seen at [2] that this is where results are censored.  This
change made it into Ansible 2.5.  Ergo this callback will never see
uncensored results here.

The second part of the no_log processing here was added with
I9e8d08f75207b362ca23457c44cc2f38ff43ac23 in March 2018.  This was to
work around an issue with loops, where the uncensored values would
"leak" into the results under certain circumstances when using loops,
e.g.

 - name: A templated no_log loop
   a_task:
     a_arg: 'foo'
   no_log: '{{ item }}'
   loop:
     - True
     - False

Ansible merged a few changes related to fixing this.  [3] was merged
in June 2018 for this exact issue of unreachable hosts.  [4] was
merged in August 2018, which makes it so that if any loop item is
"no_log", the whole task is.  Both of these changes made it into
Ansible 2.7.

Ansible has merged test-cases for these, but we have also merged
test-cases, so we have double coverage against regression in the
future.

Ergo, I believe we can revert both of these checks.  This also means
we don't have to worry about special-casing string results as done in
I02bcd307bcfad8d99dd0db13d979ce7ba3d5e0e4.

[1] 01b6c7c9c6
[2] f7c2b1986c/lib/ansible/executor/task_result.py (L13)
[3] 336b3762b2
[4] bda074d34e

Change-Id: I00ef08869f3a8f08a1affa5e15e3386a1891f11e
This commit is contained in:
Ian Wienand 2022-04-28 09:55:06 +10:00
parent 4e89ea4e18
commit 7996f634fa

View File

@ -135,35 +135,12 @@ class CallbackModule(CallbackBase):
def v2_runner_on_ok(self, result, **kwargs):
host = result._host
action = result._task.action
if result._result.get('_ansible_no_log', False) or result._task.no_log:
self.results[-1]['tasks'][-1]['hosts'][host.name] = dict(
censored="the output has been hidden due to the fact that"
" 'no_log: true' was specified for this result")
else:
# strip_internal_keys makes a deep copy of dict items, but
# not lists, so we need to create our own complete deep
# copy first so we don't modify the original.
myresult = copy.deepcopy(result._result)
clean_result = strip_internal_keys(myresult)
for index, item_result in enumerate(
clean_result.get('results', [])):
# If in a loop, this will be a list of result
# dictionaries. Otherwise for other tasks
# (yum/package are examples) each entry is a string.
if not hasattr(item_result, 'get'):
continue
# NOTE(ianw) 2022-04-21 : it is not entirely clear if
# results having _ansible_no_log here has actually
# been fixed upstream. For an abundance of caution,
# leave this.
if not item_result.get('_ansible_no_log', False):
continue
clean_result['results'][index] = dict(
censored="the output has been hidden due to the fact that"
" 'no_log: true' was specified for this result")
self.results[-1]['tasks'][-1]['hosts'][host.name] = clean_result
# strip_internal_keys makes a deep copy of dict items, but
# not lists, so we need to create our own complete deep
# copy first so we don't modify the original.
myresult = copy.deepcopy(result._result)
clean_result = strip_internal_keys(myresult)
self.results[-1]['tasks'][-1]['hosts'][host.name] = clean_result
end_time = current_time()
self.results[-1]['tasks'][-1]['task']['duration']['end'] = end_time
self.results[-1]['play']['duration']['end'] = end_time