From 3f17a39238f7aaaebaf33ffe5f29884d0f732765 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Sun, 9 Jun 2013 12:17:57 -0400 Subject: [PATCH 1/2] Set current play/task to None for callback context when finished running the current play/task. --- lib/ansible/playbook/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index c2e43187ce4..8b69d19a0e3 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -213,10 +213,7 @@ class PlayBook(object): self.callbacks.on_start() for (play_ds, play_basedir) in zip(self.playbook, self.play_basedirs): play = Play(self, play_ds, play_basedir) - assert play is not None - ansible.callbacks.set_play(self.callbacks, play) - ansible.callbacks.set_play(self.runner_callbacks, play) matched_tags, unmatched_tags = play.compare_tags(self.only_tags) matched_tags_all = matched_tags_all | matched_tags @@ -242,8 +239,12 @@ class PlayBook(object): raise errors.AnsibleError(msg % (unknown, unmatched)) for play in plays: + ansible.callbacks.set_play(self.callbacks, play) + ansible.callbacks.set_play(self.runner_callbacks, play) if not self._run_play(play): break + ansible.callbacks.set_play(self.callbacks, None) + ansible.callbacks.set_play(self.runner_callbacks, None) # summarize the results results = {} @@ -325,6 +326,8 @@ class PlayBook(object): self.callbacks.on_task_start(template(play.basedir, task.name, task.module_vars, lookup_fatal=False), is_handler) if hasattr(self.callbacks, 'skip_task') and self.callbacks.skip_task: + ansible.callbacks.set_task(self.callbacks, None) + ansible.callbacks.set_task(self.runner_callbacks, None) return True # load up an appropriate ansible runner to run the task in parallel @@ -365,6 +368,8 @@ class PlayBook(object): for handler_name in task.notify: self._flag_handler(play, template(play.basedir, handler_name, task.module_vars), host) + ansible.callbacks.set_task(self.callbacks, None) + ansible.callbacks.set_task(self.runner_callbacks, None) return hosts_remaining # ***************************************************** From d1de7839d792b1a1378f3e9b95d8ebea48c2a607 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Sun, 9 Jun 2013 12:19:07 -0400 Subject: [PATCH 2/2] Renamed on_no_hosts_matched/on_no_hosts_remaining to correct names in noop callback, added methods to callback plugin examples. --- lib/ansible/callback_plugins/noop.py | 4 ++-- plugins/callbacks/log_plays.py | 6 ++++++ plugins/callbacks/osx_say.py | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/ansible/callback_plugins/noop.py b/lib/ansible/callback_plugins/noop.py index 826bad0f7ea..54a2b254fc7 100644 --- a/lib/ansible/callback_plugins/noop.py +++ b/lib/ansible/callback_plugins/noop.py @@ -63,10 +63,10 @@ class CallbackModule(object): def playbook_on_notify(self, host, handler): pass - def on_no_hosts_matched(self): + def playbook_on_no_hosts_matched(self): pass - def on_no_hosts_remaining(self): + def playbook_on_no_hosts_remaining(self): pass def playbook_on_task_start(self, name, is_conditional): diff --git a/plugins/callbacks/log_plays.py b/plugins/callbacks/log_plays.py index 41c5d1b86a7..8f037d6b1a3 100644 --- a/plugins/callbacks/log_plays.py +++ b/plugins/callbacks/log_plays.py @@ -90,6 +90,12 @@ class CallbackModule(object): def playbook_on_notify(self, host, handler): pass + def playbook_on_no_hosts_matched(self): + pass + + def playbook_on_no_hosts_remaining(self): + pass + def playbook_on_task_start(self, name, is_conditional): pass diff --git a/plugins/callbacks/osx_say.py b/plugins/callbacks/osx_say.py index 89c82ca5304..9f6763c100f 100644 --- a/plugins/callbacks/osx_say.py +++ b/plugins/callbacks/osx_say.py @@ -67,6 +67,12 @@ class CallbackModule(object): def playbook_on_notify(self, host, handler): say("pew", LASER_VOICE) + def playbook_on_no_hosts_matched(self): + pass + + def playbook_on_no_hosts_remaining(self): + pass + def playbook_on_task_start(self, name, is_conditional): if not is_conditional: say("Starting task: %s" % name, REGULAR_VOICE)