From 6012646d8c5301b3b5fa63d58e5269af08275449 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 2 Dec 2015 20:36:21 -0800 Subject: [PATCH] added playbook and options info to callbacks will display on certain verbosity levels, both playbook/file info and non empty options with which it's running. avoid errors when not using CLI classes --- lib/ansible/plugins/callback/__init__.py | 10 ++++++++++ lib/ansible/plugins/callback/default.py | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index 58904420af..ce0361700c 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -39,6 +39,11 @@ except ImportError: __all__ = ["CallbackBase"] +try: + from __main__ import cli +except ImportError: + # using API w/o cli + cli = False class CallbackBase: @@ -54,6 +59,11 @@ class CallbackBase: else: self._display = global_display + if cli: + self._options = cli.options + else: + self._options = None + if self._display.verbosity >= 4: name = getattr(self, 'CALLBACK_NAME', 'unnamed') ctype = getattr(self, 'CALLBACK_TYPE', 'old') diff --git a/lib/ansible/plugins/callback/default.py b/lib/ansible/plugins/callback/default.py index df32112cb3..9d6c9d8c5b 100644 --- a/lib/ansible/plugins/callback/default.py +++ b/lib/ansible/plugins/callback/default.py @@ -230,3 +230,16 @@ class CallbackModule(CallbackBase): self._display.display("", screen_only=True) + def v2_playbook_on_start(self, playbook): + if self._display.verbosity > 1: + from os.path import basename + self._display.banner("PLAYBOOK: %s" % basename(playbook._file_name)) + + if self._display.verbosity > 3: + if self._options is not None: + for option in dir(self._options): + if option.startswith('_') or option in ['read_file', 'ensure_value', 'read_module']: + continue + val = getattr(self._options,option) + if val: + self._display.vvvv('%s: %s' % (option,val))