Make on_file_diff callback item-aware
This commit is contained in:
parent
04d74fd680
commit
14e19c239d
4 changed files with 22 additions and 4 deletions
|
@ -59,6 +59,10 @@ class CallbackBase:
|
|||
version = getattr(self, 'CALLBACK_VERSION', '1.0')
|
||||
self._display.vvvv('Loaded callback %s of type %s, v%s' % (name, ctype, version))
|
||||
|
||||
def _copy_result(self, result):
|
||||
''' helper for callbacks, so they don't all have to include deepcopy '''
|
||||
return deepcopy(result)
|
||||
|
||||
def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=False):
|
||||
if result.get('_ansible_no_log', False):
|
||||
return json.dumps(dict(censored="the output has been hidden due to the fact that 'no_log: true' was specified for this result"))
|
||||
|
@ -126,7 +130,7 @@ class CallbackBase:
|
|||
|
||||
def _process_items(self, result):
|
||||
for res in result._result['results']:
|
||||
newres = deepcopy(result)
|
||||
newres = self._copy_result(result)
|
||||
res['item'] = self._get_item(res)
|
||||
newres._result = res
|
||||
if 'failed' in res and res['failed']:
|
||||
|
|
|
@ -134,7 +134,14 @@ class CallbackModule(CallbackBase):
|
|||
self._display.banner(msg)
|
||||
|
||||
def v2_on_file_diff(self, result):
|
||||
if 'diff' in result._result and result._result['diff']:
|
||||
if result._task.loop and 'results' in result._result:
|
||||
for res in result._result['results']:
|
||||
newres = self._copy_result(result)
|
||||
res['item'] = self._get_item(res)
|
||||
newres._result = res
|
||||
|
||||
self.v2_on_file_diff(newres)
|
||||
elif 'diff' in result._result and result._result['diff']:
|
||||
self._display.display(self._get_diff(result._result['diff']))
|
||||
|
||||
def v2_playbook_item_on_ok(self, result):
|
||||
|
|
|
@ -123,7 +123,14 @@ class CallbackModule(CallbackBase):
|
|||
self._display.banner(msg)
|
||||
|
||||
def v2_on_file_diff(self, result):
|
||||
if 'diff' in result._result and result._result['diff']:
|
||||
if result._task.loop and 'results' in result._result:
|
||||
for res in result._result['results']:
|
||||
newres = self._copy_result(result)
|
||||
res['item'] = self._get_item(res)
|
||||
newres._result = res
|
||||
|
||||
self.v2_on_file_diff(newres)
|
||||
elif 'diff' in result._result and result._result['diff']:
|
||||
self._display.display(self._get_diff(result._result['diff']))
|
||||
|
||||
def v2_playbook_item_on_ok(self, result):
|
||||
|
|
|
@ -221,7 +221,7 @@ class StrategyBase:
|
|||
self._tqm._stats.increment('changed', host.name)
|
||||
self._tqm.send_callback('v2_runner_on_ok', task_result)
|
||||
|
||||
if self._diff and 'diff' in task_result._result:
|
||||
if self._diff:
|
||||
self._tqm.send_callback('v2_on_file_diff', task_result)
|
||||
|
||||
self._pending_results -= 1
|
||||
|
|
Loading…
Reference in a new issue