# Callback plugin with Ansible 2.0

**URL:** <https://forum.ansible.com/t/callback-plugin-with-ansible-2-0/22404>\
**Category:** Ansible Developer\
**Created:** [August 26, 2016, 7:38pm UTC](https://forum.ansible.com/t/callback-plugin-with-ansible-2-0/22404 "2016-08-26T19:38:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_S](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sam\_S](https://forum.ansible.com/u/Sam_S)\
**Post date:** [August 26, 2016, 7:38pm UTC](https://forum.ansible.com/t/callback-plugin-with-ansible-2-0/22404/1 "2016-08-26T19:38:06Z")

</div>

I inherited a callback plugin that was woirking with Ansible 1.9. We upgraded to 2.1 and it no longer works.

Looks like it’s trying to access the playbook object but it’s not getting passed into “v2\_playbook\_on\_stats.” My Python is rusty so I’m not sure how I can go about accessing that data. I’m tryijng to access the “extra-vars” variable but it’s giving me the following error:

[WARNING]: Failure using method (v2\_playbook\_on\_stats) in callback plugin  
(\</home/deployment/scripts/playbooks-2.0/callback/log\_to\_mongo.CallbackModule object at 0x2b8cf90\>): ‘NoneType’ object has no  
attribute ‘extra\_vars’

class CallbackModule(object):  
“”"  
An ansible callback module for saving Ansible output to a database log  
“”"  
def **init** (self):  
self.playbook = None  
self.playbook\_name = None  
self.play = None  
self.task = None

CALLBACK\_VERSION = 2.0  
CALLBACK\_TYPE = ‘notification’  
CALLBACK\_NAME = ‘log\_to\_mongo’  
CALLBACK\_NEEDS\_WHITELIST = False

def v2\_playbook\_on\_stats(self, stats):  
global jira\_ticket  
global deployed\_modules  
global ocd\_job\_id  
global environment\_id

deployed\_modules =   
jira\_ticket = self.playbook.extra\_vars[‘jira\_ticket’]  
ocd\_job\_id = self.playbook.extra\_vars[‘ocd\_job\_id’]  
environment\_id = self.playbook.extra\_vars[‘environment\_id’]

---

<div class="post-metadata">

**Author:** ![Raja1](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Raja1](https://forum.ansible.com/u/Raja1)\
**Post date:** [August 27, 2016, 2:14am UTC](https://forum.ansible.com/t/callback-plugin-with-ansible-2-0/22404/2 "2016-08-27T02:14:50Z")

</div>

I think the mechanism changed in Ansible 2. You might have to get your play object in v2\_playbook\_on\_play\_start and then use that variable in on\_stats . Something like

class CallbackModule(object):  
def **init** (self):  
super(CallbackModule,self). **init** ()  
self.play = None

def v2\_playbook\_on\_play\_start(self, play):  
self.play = play

…

def v2\_playbook\_on\_stats(self, stats):  
extra\_vars = self.play.\_variable\_manager.extra\_vars  
jira\_ticket = extra\_vars[‘jira\_ticket’]

---

<div class="post-metadata">

**Author:** ![Sam\_S](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sam\_S](https://forum.ansible.com/u/Sam_S)\
**Post date:** [August 27, 2016, 2:21am UTC](https://forum.ansible.com/t/callback-plugin-with-ansible-2-0/22404/3 "2016-08-27T02:21:01Z")

</div>

THANK YOU!!!

Now how the heck do I track down all these changes? I like v2 but it broke a lot of things.

---

<div class="post-metadata">

**Author:** ![Jason\_DeTiberus](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@Jason\_DeTiberus](https://forum.ansible.com/u/Jason_DeTiberus)\
**Post date:** [August 27, 2016, 7:22am UTC](https://forum.ansible.com/t/callback-plugin-with-ansible-2-0/22404/4 "2016-08-27T07:22:54Z")

</div>

Sam,

Does this page help: [https://docs.ansible.com/ansible/porting\_guide\_2.0.html#callback-plugins](https://docs.ansible.com/ansible/porting_guide_2.0.html#callback-plugins)?

---

<div class="post-metadata">

**Author:** ![Sam\_S](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sam\_S](https://forum.ansible.com/u/Sam_S)\
**Post date:** [August 29, 2016, 2:26pm UTC](https://forum.ansible.com/t/callback-plugin-with-ansible-2-0/22404/5 "2016-08-29T14:26:18Z")

</div>

Not really. This is highly frustrated, but I’m speaking for myself.

So for example, I can’t figure out where certain methods are. Other folks are also expressing the same feelings.

Case in point:

To get extra vars I can use the following line in v2.

extra\_vars = self.play.\_variable\_manager.extra\_vars

jira\_ticket = extra\_vars[‘jira\_ticket’]

Old method:

jira\_ticket = self.playbook.extra\_vars[‘jira\_ticket’]

Now I’m trying to chase down where the var cache are located.
