# Buggy code
def set_options(self, options):
    super(CallbackModule, self).set_options(options)

    # get options
    try:
        self.api_url = self._plugin_options["api"]
        self.api_port = self._plugin_options["port"]
        self.api_tls_port = self._plugin_options["tls_port"]
        self.use_tls = self._plugin_options["use_tls"]
        self.flatten = self._plugin_options["flatten"]
    except KeyError as e:
        self._display.warning(
            "Missing option for Logentries callback plugin: %s" % to_native(e)
        )
        self.disabled = True

    try:
        self.token = self._plugin_options["token"]
    except KeyError as e:
        self._display.warning(
            "Logentries token was not provided, this is required for this callback to operate, disabling"
        )
        self.disabled = True

    if self.flatten and not HAS_FLATDICT:
        self.disabled = True
        self._display.warning(
            "You have chosen to flatten and the `flatdict` python module is not installed.\nDisabling the Logentries callback plugin."
        )

    self._initialize_connections()


# Traceback (TypeError)
$ ansible-playbook test_play.yml -vvv
ansible-playbook 2.5.0 (devel a40ce1ba5e) last updated 2017/11/17 16:31:10 (GMT +1000)
config file = /home/will/src/ansible/ansible.cfg
configured module search path = [u'/home/will/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/will/src/ansible/lib/ansible
executable location = /home/will/src/ansible/bin/ansible-playbook
python version = 2.7.14 (default, Nov  2 2017, 18:42:05) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]
Using /home/will/src/ansible/ansible.cfg as config file
Parsed /etc/ansible/hosts inventory source with ini plugin
[WARNING]: Could not match supplied host pattern, ignoring: all

[WARNING]: provided hosts list is empty, only localhost is available

ERROR! Unexpected Exception, this is probably a bug: set_options() takes exactly 2 arguments (1 given)
the full traceback was:

Traceback (most recent call last):
File "/home/will/src/ansible/bin/ansible-playbook", line 109, in <module>
exit_code = cli.run()
File "/home/will/src/ansible/lib/ansible/cli/playbook.py", line 130, in run
results = pbex.run()
File "/home/will/src/ansible/lib/ansible/executor/playbook_executor.py", line 90, in run
self._tqm.load_callbacks()
File "/home/will/src/ansible/lib/ansible/executor/task_queue_manager.py", line 210, in load_callbacks
callback_obj.set_options()
TypeError: set_options() takes exactly 2 arguments (1 given)

# Fixed code
def set_options(self, task_keys=None, var_options=None, direct=None):
    super(CallbackModule, self).set_options(
        task_keys=task_keys, var_options=var_options, direct=direct
    )

    # get options
    try:
        self.api_url = self._plugin_options["api"]
        self.api_port = self._plugin_options["port"]
        self.api_tls_port = self._plugin_options["tls_port"]
        self.use_tls = self._plugin_options["use_tls"]
        self.flatten = self._plugin_options["flatten"]
    except KeyError as e:
        self._display.warning(
            "Missing option for Logentries callback plugin: %s" % to_native(e)
        )
        self.disabled = True

    try:
        self.token = self._plugin_options["token"]
    except KeyError as e:
        self._display.warning(
            "Logentries token was not provided, this is required for this callback to operate, disabling"
        )
        self.disabled = True

    if self.flatten and not HAS_FLATDICT:
        self.disabled = True
        self._display.warning(
            "You have chosen to flatten and the `flatdict` python module is not installed.\nDisabling the Logentries callback plugin."
        )

    self._initialize_connections()