1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix task banner with 'actionable' callback when using templates in name (#38165)

This fixes #31074.
This commit is contained in:
Andrew Gaffney 2018-05-09 12:57:28 -05:00 committed by Brian Coca
parent dec4f10c21
commit ff16e993be

View file

@ -20,6 +20,7 @@ DOCUMENTATION = '''
- set as stdout callback in configuration
'''
from ansible import constants as C
from ansible.plugins.callback.default import CallbackModule as CallbackModule_default
@ -33,6 +34,7 @@ class CallbackModule(CallbackModule_default):
self.super_ref = super(CallbackModule, self)
self.super_ref.__init__()
self.last_task = None
self.last_task_banner = None
self.shown_title = False
def v2_playbook_on_handler_task_start(self, task):
@ -41,6 +43,7 @@ class CallbackModule(CallbackModule_default):
def v2_playbook_on_task_start(self, task, is_conditional):
self.last_task = task
self.last_task_banner = self._get_task_banner(task)
self.shown_title = False
def display_task_banner(self):
@ -48,6 +51,33 @@ class CallbackModule(CallbackModule_default):
self.super_ref.v2_playbook_on_task_start(self.last_task, None)
self.shown_title = True
def _print_task_banner(self, task):
self._display.banner(self.last_task_banner)
self._print_task_path(self.last_task)
self._last_task_banner = self.last_task._uuid
def _print_task_path(self, task):
if self._display.verbosity >= 2:
path = task.get_path()
if path:
self._display.display(u"task path: %s" % path, color=C.COLOR_DEBUG)
def _get_task_banner(self, task):
# args can be specified as no_log in several places: in the task or in
# the argument spec. We can check whether the task is no_log but the
# argument spec can't be because that is only run on the target
# machine and we haven't run it thereyet at this time.
#
# So we give people a config option to affect display of the args so
# that they can secure this if they feel that their stdout is insecure
# (shoulder surfing, logging stdout straight to a file, etc).
args = ''
if not task.no_log and C.DISPLAY_ARGS_TO_STDOUT:
args = u', '.join(u'%s=%s' % a for a in task.args.items())
args = u' %s' % args
return u"TASK [%s%s]" % (task.get_name().strip(), args)
def v2_runner_on_failed(self, result, ignore_errors=False):
self.display_task_banner()
self.super_ref.v2_runner_on_failed(result, ignore_errors)