# Callback-Plugins seem to have one instance per fork - how to synchronize them?

**URL:** <https://forum.ansible.com/t/callback-plugins-seem-to-have-one-instance-per-fork-how-to-synchronize-them/19864>\
**Category:** Ansible Project\
**Created:** [November 26, 2015, 1:26pm UTC](https://forum.ansible.com/t/callback-plugins-seem-to-have-one-instance-per-fork-how-to-synchronize-them/19864 "2015-11-26T13:26:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Wenig](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Michael\_Wenig](https://forum.ansible.com/u/Michael_Wenig)\
**Post date:** [November 26, 2015, 1:26pm UTC](https://forum.ansible.com/t/callback-plugins-seem-to-have-one-instance-per-fork-how-to-synchronize-them/19864/1 "2015-11-26T13:26:36Z")

</div>

Hi,

we have a callback plugin (Ansible 1.8.4) which gathers information during the playbook run and stores them in a class-local variable.  
On playbook end this should be displayed in the log (e.g. warnings and errors found)

Here is the relevant code:

class CallbackModule(object):

…

saved\_logs = {}

def runner\_on\_failed(self, host, res, ignore\_errors=False):  
… put something in saved\_logs

def runner\_on\_ok(self, host, res):  
… put something in saved\_logs

def runner\_on\_error(self, host, msg):  
… put something in saved\_logs

def runner\_on\_skipped(self, host, item=None):  
… put something in saved\_logs

def playbook\_on\_stats(self, stats):  
… display contents of saved\_logs

Now it seems that the Callback gets one instance per fork as we only see in stats the content which was added by tasks running on the controller. Logs generated e.g. in modules running on the nodes are only available in stats if “fork” is set to 1

Is this behaviour intentional?

How should we fix/synchronize this?

Regards Michael

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [November 27, 2015, 4:36pm UTC](https://forum.ansible.com/t/callback-plugins-seem-to-have-one-instance-per-fork-how-to-synchronize-them/19864/2 "2015-11-27T16:36:55Z")

</div>

I think the problem is that you are using a class attribute for saved\_logs as opposed to an instance attribute.

An instance attribute would be instatiated in **init** () and because Ansible instantiates the class 1 time and passes that instance to all forks you shouldn’t have that problem.

---

<div class="post-metadata">

**Author:** ![Michael\_Wenig](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Michael\_Wenig](https://forum.ansible.com/u/Michael_Wenig)\
**Post date:** [November 30, 2015, 6:41am UTC](https://forum.ansible.com/t/callback-plugins-seem-to-have-one-instance-per-fork-how-to-synchronize-them/19864/3 "2015-11-30T06:41:58Z")

</div>

Hi,

but we _need_ to have a class attribute - I do not want one variable per instance but _one_ Variable which holds _all_ logs of _all_ forks.

So a class-variable should be the right one. Unfortunately it seems that the instance gets copied for every fork and is not synchronized back.

Regards Michael
