After going through the Ansible code, I was able to solve it using below ...
In each callback_plugin you can specify self.disabled = True , and callback will not be called at all ...
In addition, when calling the playbook, it is possible to parse additional arguments as a key=value pair. It will be part of the playbook object as an extra_vars field.
So, I did something like this in callback_plugin .
def playbook_on_start(self): callback_plugins = self.playbook.extra_vars.get('callback_plugin', '') // self.playbook is populated in your callback plugin by Ansible. if callback_plugins not in ['email_reporter', 'all']: self.disabled = True
And when calling the playbook, I can do something like
ansible-playbook -e callback_plugin=email_reporter //Note -e is the argument prefix key for extra vars.
source share