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

20 views
Skip to first unread message

Michael Wenig

unread,
Nov 27, 2015, 11:06:30 AM11/27/15
to Ansible Project
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

Matt Martz

unread,
Nov 27, 2015, 11:37:03 AM11/27/15
to ansible...@googlegroups.com
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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f0671c97-6361-4cc9-9dd6-29abac493975%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Michael Wenig

unread,
Nov 30, 2015, 1:41:58 AM11/30/15
to Ansible Project
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
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages