Fix no_log bug with result lists
The combination of with_items, register, and no_log meant that we were modifying a list which was a shared reference between the results object used by ansible and that which we log to json. Make a deep copy of the results object before we modify it so that we don't modify the "original". Also, correct a comment about the location of an import. This adds a test which fails without the fix. Change-Id: Iaab94f4ac8a0f58089912e464f6dfcf2e5f8ce71
This commit is contained in:
parent
fe0274cfca
commit
a7aa174826
|
@ -9,3 +9,31 @@
|
|||
msg: setec astronomy
|
||||
no_log: true
|
||||
with_sequence: start=0 end=2
|
||||
# The next section tests that the results object is still usable
|
||||
# by other tasks even if we're censoring the output in zuul_json.
|
||||
- name: Find files
|
||||
block:
|
||||
- name: Create file
|
||||
copy:
|
||||
content: ""
|
||||
dest: "{{ ansible_user_dir }}/setec_astronomy"
|
||||
|
||||
- name: Find files
|
||||
find:
|
||||
path: "{{ ansible_user_dir }}"
|
||||
file_type: any
|
||||
register: src_files
|
||||
|
||||
- name: Dereference files
|
||||
stat:
|
||||
path: "{{ item.path }}"
|
||||
with_items: "{{ src_files.files }}"
|
||||
register: src_paths
|
||||
|
||||
- name: Print path
|
||||
debug:
|
||||
msg: "{{ item.stat.path }}"
|
||||
when:
|
||||
- item.stat.isreg
|
||||
with_items: "{{ src_paths.results }}"
|
||||
no_log: true
|
||||
|
|
|
@ -22,15 +22,16 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
try:
|
||||
# It's here in 2.4
|
||||
# It's here in 2.3
|
||||
from ansible.vars import strip_internal_keys
|
||||
except ImportError:
|
||||
# It's here in 2.3
|
||||
# It's here in 2.4
|
||||
from ansible.vars.manager import strip_internal_keys
|
||||
|
||||
from zuul.ansible import logconfig
|
||||
|
@ -120,7 +121,11 @@ class CallbackModule(CallbackBase):
|
|||
censored="the output has been hidden due to the fact that"
|
||||
" 'no_log: true' was specified for this result")
|
||||
else:
|
||||
clean_result = strip_internal_keys(result._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)
|
||||
|
||||
for index, item_result in enumerate(
|
||||
clean_result.get('results', [])):
|
||||
|
|
Loading…
Reference in New Issue