summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael DeHaan <michael@ansibleworks.com>2013-03-25 22:56:32 -0400
committerMichael DeHaan <michael@ansibleworks.com>2013-03-25 22:56:32 -0400
commit42b0e51223562bcf94d23cec8518c60606927e58 (patch)
treea7d4a035fcc09360fd3b93a1e4a4178698e4b81c
parent5b845510b3a45cc9667e796af47c3507b83df85c (diff)
downloadansible-42b0e51223562bcf94d23cec8518c60606927e58.tar.gz
Upgrade callbacks further, now '.play', '.task', and so on are also available!
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/ansible/playbook/__init__.py10
2 files changed, 11 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a0d337a3ca..02cc6b4ff5 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 a38a328e3d..c47ac7a075 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(