ansible zuul_json callback : handle string results

We have noted a problem with tasks such as "yum:" or "package:" that
output is not being logged in the job json file.

After investigation, I have found that this is failing with an
exception in the results parsing at

   for index, item_result in enumerate(
           clean_result.get('results', [])):
       if not item_result.get('_ansible_no_log', False):
           continue

When we are *not* processing a task loop, "results" is a simple list
of strings about the package results; thus when it walks each result
the "item_result.get('_ansible_no_log', False)" step fails because a
string has no ".get()".  This causes the plugin to exit and the
information in the resulting .json to be incomplete, leading to the
tasks being missing from the UI.  I believe this was a regression
introduced with I9e8d08f75207b362ca23457c44cc2f38ff43ac23.

When we *are* processing a task loop, "results" is a list where each
entry is a loop-item result.  In this case, we are always walking a
list of dictionaries, so the existing ".get()" call works.

Change-Id: I02bcd307bcfad8d99dd0db13d979ce7ba3d5e0e4
This commit is contained in:
Ian Wienand
2022-04-21 18:23:57 +10:00
parent 8582dac3ad
commit bc45371fdd

View File

@@ -148,6 +148,15 @@ class CallbackModule(CallbackBase):
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(