cat ansible.cfgjson
callback_whitelist = timer, mail,black_hole callback_plugins = /usr/share/ansible/plugins/callback # by default callbacks are not loaded for /bin/ansible, enable this if you # want, for example, a notification or logging callback to also apply to bin_ansible_callbacks = True
cat /usr/share/ansible/plugins/callback/black_hole.pyapp
cat black_hole.py import sys import commands import MySQLdb import os import json from collections import namedtuple #from ansible.inventory import Inventory #from ansible.vars import VariableManager from ansible.parsing.dataloader import DataLoader from ansible.executor.playbook_executor import PlaybookExecutor from ansible.plugins.callback import CallbackBase from ansible.errors import AnsibleParserError from ansible.plugins.callback import CallbackBase class CallbackModule(CallbackBase): def v2_runner_on_ok(self, result): host = result._host.get_name() f = open('/tmp/result_callback', 'a+') f.write(str(host) + "aaaaaa\n") f.write(str(result._result['stdout_lines'])) f.close() def v2_runner_on_unreachable(self, result): host = result._host.get_name() f = open('/tmp/result_callback_unreachable', 'a+') f.write(str(host) + "aaaaaa\n") f.write(str(result._result['stdout_lines'])) f.close() def v2_runner_on_failed(self, result, ignore_errors=False): host = result._host.get_name() f = open('/tmp/result_callback_failed', 'a+') f.write(str(host) + "aaaaaa\n") f.write(str(result._result['stdout_lines'])) f.close()
[root@localhost tmp]# cat result_callback_unreachable 192.168.1.103aaaaaa [root@localhost tmp]# [root@localhost tmp]# ls ks-script-Bfkpe0 systemd-private-270df7a5c187446a9259969e2d81e835-chronyd.service-FhawaX yum.log result_callback systemd-private-270df7a5c187446a9259969e2d81e835-vgauthd.service-Ba59mJ result_callback_unreachable systemd-private-270df7a5c187446a9259969e2d81e835-vmtoolsd.service-jYl8Av [root@localhost tmp]# cat result_callback 192.168.1.102aaaaaa [u' 22:17:08 up 6:47, 4 users, load average: 0.00, 0.01, 0.05'][root@localhost tmp]#