How to patch a plugin

We use hostnames which often start with a numeral (we can’t do anything about this). One result of this is that errors during a play often produce a complaint from mail.CallbackModule like this:

Failure using method (v2_runner_on_failed) in callback plugin (<ansible.plugins.callback./usr/local/lib/python3.6/dist-

packages/ansible/plugins/callback/mail.CallbackModule object at 0x7f31ceb2a630>): ‘in ’ requires string as left operand, not int

I’d like to fix this plugin, preferably without overwriting the library code. Afterwards I can submit a patch.

Please can someone tell me the easiest way of doing this.

Many thanks!

First, copy the .py file for the callback plugin from the Ansible source code to an empty local directory. That file is apparently ansible/lib/ansible/plugins/callback/mail.py in your case.

Modify the 2 Ansible config settings related to the callback plugins

https://github.com/ansible/ansible/blob/5f8ec4d46e1fec49eca5c2f351141ed5da6d259e/lib/ansible/config/base.yml#L527-L546

For the callback plugin paths, copy the defaults, and then add the directory you saved the plugin to it to the start of the list, using the path separator. The name of the plugin should be in the whitelist setting, but the fact that you encountered this issue shows that you already have this configured. My only concern here is that (since you don’t remove the version from Ansible itself) your version now needs to come at higher precedence. If you have problems with it taking effect, you could try giving it a new name and put this new name in the whitelist.

Then make the patch in your local file, confirm fix, and consider contributing back the fix like you say.

Alan
github: AlanCoding

Thank you, Alan. I will try this.

(I tried to reply a few days ago via email but my message was rejected.)

Andrew