mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
By popular request, make the no_log attribute also censor tasks from callbacks.
This commit is contained in:
@@ -956,12 +956,17 @@ class Runner(object):
|
||||
if failed_when is not None and 'skipped' not in data:
|
||||
data['failed_when_result'] = data['failed'] = utils.check_conditional(failed_when, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars)
|
||||
|
||||
|
||||
if is_chained:
|
||||
# no callbacks
|
||||
return result
|
||||
if 'skipped' in data:
|
||||
self.callbacks.on_skipped(host, inject.get('item',None))
|
||||
elif not result.is_successful():
|
||||
|
||||
if self.no_log:
|
||||
data = utils.censor_unlogged_data(data)
|
||||
|
||||
if not result.is_successful():
|
||||
ignore_errors = self.module_vars.get('ignore_errors', False)
|
||||
self.callbacks.on_failed(host, data, ignore_errors)
|
||||
else:
|
||||
|
||||
@@ -1436,3 +1436,19 @@ def update_hash(hash, key, new_value):
|
||||
value = hash.get(key, {})
|
||||
value.update(new_value)
|
||||
hash[key] = value
|
||||
|
||||
def censor_unlogged_data(data):
|
||||
'''
|
||||
used when the no_log: True attribute is passed to a task to keep data from a callback.
|
||||
NOT intended to prevent variable registration, but only things from showing up on
|
||||
screen
|
||||
'''
|
||||
new_data = {}
|
||||
for (x,y) in data.iteritems():
|
||||
if x in [ 'skipped', 'changed', 'failed', 'rc' ]:
|
||||
new_data[x] = y
|
||||
new_data['censored'] = 'results hidden due to no_log parameter'
|
||||
return new_data
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user