From 42b0e51223562bcf94d23cec8518c60606927e58 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 25 Mar 2013 22:56:32 -0400 Subject: [PATCH] Upgrade callbacks further, now '.play', '.task', and so on are also available! --- CHANGELOG.md | 2 +- lib/ansible/playbook/__init__.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0d337a3ca2..02cc6b4ff59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,7 +69,7 @@ Bugfixes and Misc Changes: * 'magic' variable 'inventory_basedir' now gives path to inventory file * 'magic' variable 'vars' works like 'hostvars' but gives global scope variables, useful for debugging in templates mostly * conditionals can be used on plugins like add_host -* all callbacks now have access to a ".runner" and ".playbook" object (.playbook is only set by ansible-playbook) +* developers: all callbacks now have access to a ".runner" and ".playbook", ".play", and ".task" object (use getattr, they may not always be set!) Facts: diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index a38a328e3d8..c47ac7a0756 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -206,6 +206,10 @@ 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) + + self.callbacks.play = play + self.runner_callbacks.play = play + matched_tags, unmatched_tags = play.compare_tags(self.only_tags) matched_tags_all = matched_tags_all | matched_tags unmatched_tags_all = unmatched_tags_all | unmatched_tags @@ -306,6 +310,9 @@ class PlayBook(object): def _run_task(self, play, task, is_handler): ''' run a single task in the playbook and recursively run any subtasks. ''' + self.callbacks.task = task + self.runner_callbacks.task = task + self.callbacks.on_task_start(utils.template(play.basedir, task.name, task.module_vars, lookup_fatal=False), is_handler) if hasattr(self.callbacks, 'skip_task') and self.callbacks.skip_task: return True @@ -379,6 +386,9 @@ class PlayBook(object): self.callbacks.on_setup() self.inventory.restrict_to(host_list) + + self.callbacks.task = None + self.runner_callbacks.task = None # push any variables down to the system setup_results = ansible.runner.Runner(