# v2 callbacks for handlers inside a role

**URL:** <https://forum.ansible.com/t/v2-callbacks-for-handlers-inside-a-role/20224>\
**Category:** Ansible Developer\
**Created:** [January 15, 2016, 4:29am UTC](https://forum.ansible.com/t/v2-callbacks-for-handlers-inside-a-role/20224 "2016-01-15T04:29:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ash\_Caire](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@Ash\_Caire](https://forum.ansible.com/u/Ash_Caire)\
**Post date:** [January 15, 2016, 4:29am UTC](https://forum.ansible.com/t/v2-callbacks-for-handlers-inside-a-role/20224/1 "2016-01-15T04:29:08Z")

</div>

Hi, I’m using callbacks to hack up an AMI helper, which allows us to create AMIs in a chroot environment and tag template tasks with ‘retemplate’ that need to be run again on AMI launch - The callback handler copies any tasks and associated handlers to a YML in the chroot, which is subsequently run on AMI launch.

This implementation was working fine in v1, the script is here: [https://gist.github.com/acaire/8efd6242083fa0997eb7](https://gist.github.com/acaire/8efd6242083fa0997eb7)

I’ve modded my implementation for v2, which can be found here: [https://gist.github.com/acaire/ebf9aca92ce52a090bd1](https://gist.github.com/acaire/ebf9aca92ce52a090bd1)

It works for the most part, but I’m having trouble with the handlers presumably because of the dynamic inclusion changes.  
My initial thoughts were to use the ‘v2\_playbook\_on\_handler\_task\_start’ callback, although this callback is not always triggered (it’s rare that it won’t be, but I want to cover all my bases) so I’m hunting for something more reliable.

if I examine the ‘task’ object in ‘v2\_playbook\_on\_task\_start’, I can get the data I need from task.\_role.\_handler\_blocks[0].\_ds. i.e.:

(Pdb) task.\_role.\_handler\_blocks[0].\_ds  
{u’debug’: u"msg=‘this would ordinarily reload apache’", u’name’: u’reload apache’}

Which works for handlers specified directly in a playbook, but I can’t seem to get the same details from a role i.e. roles/foo/handlers/main.yml:

(Pdb) task.\_role.\_handler\_blocks[0].\_ds  
\*\*\* AttributeError: ‘NoneType’ object has no attribute ‘\_handler\_blocks’

I used to be able to get this from self.play.handlers() in the ‘playbook\_on\_task\_start’ callback.

Any suggestions?

Cheers

Ash
