From 384b2e023476b7bee242a5c7c70ebad0b0dfb33f Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Wed, 2 Dec 2015 11:29:51 -0600 Subject: [PATCH] Get v2_playbook_on_start working * Move self._tqm.load_callbacks() earlier to ensure that v2_on_playbook_start can fire * Pass the playbook instance to v2_on_playbook_start * Add a _file_name instance attribute to the playbook --- lib/ansible/executor/playbook_executor.py | 6 ++++-- lib/ansible/playbook/__init__.py | 3 +++ lib/ansible/plugins/callback/__init__.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index d647c8246a3..60a416af73d 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -82,6 +82,10 @@ class PlaybookExecutor: if self._tqm is None: # we are doing a listing entry = {'playbook': playbook_path} entry['plays'] = [] + else: + # make sure the tqm has callbacks loaded + self._tqm.load_callbacks() + self._tqm.send_callback('v2_playbook_on_start', pb) i = 1 plays = pb.get_plays() @@ -130,8 +134,6 @@ class PlaybookExecutor: entry['plays'].append(new_play) else: - # make sure the tqm has callbacks loaded - self._tqm.load_callbacks() self._tqm._unreachable_hosts.update(self._unreachable_hosts) # we are actually running plays diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 888299e1d9e..0ae443f8436 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -44,6 +44,7 @@ class Playbook: self._entries = [] self._basedir = os.getcwd() self._loader = loader + self._file_name = None @staticmethod def load(file_name, variable_manager=None, loader=None): @@ -61,6 +62,8 @@ class Playbook: # set the loaders basedir self._loader.set_basedir(self._basedir) + self._file_name = file_name + # dynamically load any plugins from the playbook directory for name, obj in get_all_plugin_loaders(): if obj.subdir: diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py index ccc8a7f8e53..03eb58d99db 100644 --- a/lib/ansible/plugins/callback/__init__.py +++ b/lib/ansible/plugins/callback/__init__.py @@ -246,7 +246,7 @@ class CallbackBase: def v2_runner_on_file_diff(self, result, diff): pass #no v1 correspondance - def v2_playbook_on_start(self): + def v2_playbook_on_start(self, playbook): self.playbook_on_start() def v2_playbook_on_notify(self, result, handler):