How to add a callback plugin to a PlaybookExecutor in Ansible 2
<p>How to specify a callback when calling ansible via its API?</p>

<p>I have a callback plugin <code>database_write.py</code> for ansible 2.0.0.2 that logs into a database when this is run:</p>

<pre><code>ansible-playbook -i inventory.txt playbook.yml # callback is fired ok
</code></pre>

<p>This works ok because in my $PWD i have <code>ansible.cfg</code> with this line:</p>

<pre><code>callback_plugins   = ./src/callback
</code></pre>

<p>Now I'm trying to make ansible to execute my playbook and my callback using the python API. I've basically copied what the ansible-playbook cli tool does </p>

<pre><code># based on https://github.com/ansible/ansible/blob/v2.0.0.2-1/lib/ansible/cli/playbook.py
pbex = PlaybookExecutor(playbooks=['../playbook.yml'],
                        inventory=inventory,
                        variable_manager=variable_manager,
                        loader=loader,
                        options=options,
                        passwords=passwords)

results = pbex.run()
</code></pre>

<p>This executes the playbook fine, <em>but the callback is not triggered.</em></p>

<p>I guess when using the python API, my <code>ansible.cfg</code> file is not being taken into account?</p>

<p><strong>how do I specify my callback plugin to the PlaybookExecutor?</strong></p>

<p>(most of the documentation I've found works for ansible versions &lt; 2.0)</p>

<p>thank you in advance!</p>