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
I’ve modded my implementation for v2, which can be found here: 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