{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/10019","labels_url":"https://api.github.com/repos/ansible/ansible/issues/10019/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/10019/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/10019/events","html_url":"https://github.com/ansible/ansible/issues/10019","id":54572503,"number":10019,"title":"Feature request: send all logs to syslog ","user":{"login":"r1k0","id":238676,"avatar_url":"https://avatars.githubusercontent.com/u/238676?v=3","gravatar_id":"","url":"https://api.github.com/users/r1k0","html_url":"https://github.com/r1k0","followers_url":"https://api.github.com/users/r1k0/followers","following_url":"https://api.github.com/users/r1k0/following{/other_user}","gists_url":"https://api.github.com/users/r1k0/gists{/gist_id}","starred_url":"https://api.github.com/users/r1k0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r1k0/subscriptions","organizations_url":"https://api.github.com/users/r1k0/orgs","repos_url":"https://api.github.com/users/r1k0/repos","events_url":"https://api.github.com/users/r1k0/events{/privacy}","received_events_url":"https://api.github.com/users/r1k0/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/feature_idea","name":"feature_idea","color":"006b75"},{"url":"https://api.github.com/repos/ansible/ansible/labels/P3","name":"P3","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-01-16T12:55:24Z","updated_at":"2015-01-27T12:13:49Z","closed_at":null,"body":"Hello,\r\n\r\n##### Issue Type:\r\n\r\nFeature request\r\n\r\n##### Ansible Version:\r\n\r\n1.8.2\r\n\r\n##### Environment:\r\n\r\nrunning from arch to a RH pool.\r\n\r\n##### Summary:\r\n\r\nAt work we manage hundreds (if not more) RH VMs with ansible.\r\nWe are several in the team to push changes. It happens that things break once in a while and we have no current way of tracking who did what since all users are runnign ansible from their machine.\r\n\r\nWe would love to have the possibility to send every ansible-playbook (and ansible too) run to syslog.\r\nWe have a syslog server in the network where we would like to send events to.\r\n\r\n##### Steps To Reproduce:\r\n\r\nnone\r\n\r\n##### Expected Results:\r\n\r\nuser should be able to send ansible stdout to syslog with info like:\r\n-  hostname, user, ip, command run and output.\r\n\r\n##### Actual Results:\r\n\r\nno syslog compatibility.\r\n\r\n\r\n\r\n\r\nthank you for the good work\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/71638648","html_url":"https://github.com/ansible/ansible/issues/10019#issuecomment-71638648","issue_url":"https://api.github.com/repos/ansible/ansible/issues/10019","id":71638648,"user":{"login":"r1k0","id":238676,"avatar_url":"https://avatars.githubusercontent.com/u/238676?v=3","gravatar_id":"","url":"https://api.github.com/users/r1k0","html_url":"https://github.com/r1k0","followers_url":"https://api.github.com/users/r1k0/followers","following_url":"https://api.github.com/users/r1k0/following{/other_user}","gists_url":"https://api.github.com/users/r1k0/gists{/gist_id}","starred_url":"https://api.github.com/users/r1k0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r1k0/subscriptions","organizations_url":"https://api.github.com/users/r1k0/orgs","repos_url":"https://api.github.com/users/r1k0/repos","events_url":"https://api.github.com/users/r1k0/events{/privacy}","received_events_url":"https://api.github.com/users/r1k0/received_events","type":"User","site_admin":false},"created_at":"2015-01-27T12:13:49Z","updated_at":"2015-01-27T12:13:49Z","body":"Here is our working callback plugin to log to a syslog server.\r\n```python\r\n  1 import os\r\n  2 import json\r\n  3 \r\n  4 import logging\r\n  5 import logging.handlers\r\n  6 \r\n  7 ansible_logger = logging.getLogger('ansible logger')\r\n  8 ansible_logger.setLevel(logging.DEBUG)\r\n  9 handler = logging.handlers.SysLogHandler(address = ('localhost',514), facility=19)\r\n 10 ansible_logger.addHandler(handler)\r\n 11 \r\n 12 class CallbackModule(object):\r\n 13     \"\"\"\r\n 14     logs ansible-playbook and ansible runs to a syslog server in json format\r\n 15     make sure you have in ansible.cfg:\r\n 16         callback_plugins   = <path_to_callback_plugins_folder>\r\n 17     and put the plugin in <path_to_callback_plugins_folder>\r\n 18     \"\"\"\r\n 19 \r\n 20     def __init__(self):\r\n 21         pass\r\n 22 \r\n 23     def on_any(self, *args, **kwargs):\r\n 24         pass\r\n 25 \r\n 26     def runner_on_failed(self, host, res, ignore_errors=False):\r\n 27         ansible_logger.info('RUNNER_ON_FAILED ' + host + ' ' + json.dumps(res, sort_keys=True))\r\n 28 \r\n 29     def runner_on_ok(self, host, res):\r\n 30         ansible_logger.info('RUNNER_ON_OK ' + host + ' ' + json.dumps(res, sort_keys=True))\r\n 31 \r\n 32     def runner_on_skipped(self, host, item=None):\r\n 33         ansible_logger.info('RUNNER_ON_SKIPPED ' + host + ' ...')\r\n 34 \r\n 35     def runner_on_unreachable(self, host, res):\r\n 36         ansible_logger.info('RUNNER_UNREACHABLE ' + host + ' ' + json.dumps(res, sort_keys=True))\r\n 37 \r\n 38     def runner_on_no_hosts(self):\r\n 39         pass\r\n 40 \r\n 41     def runner_on_async_poll(self, host, res):\r\n 42         pass\r\n 43 \r\n 44     def runner_on_async_ok(self, host, res):\r\n 45         pass\r\n 46 \r\n 47     def runner_on_async_failed(self, host, res):\r\n 48         ansible_logger.info('RUNNER_SYNC_FAILED ' + host + ' ' + json.dumps(res, sort_keys=True))\r\n 49 \r\n 50     def playbook_on_start(self):\r\n 51         pass\r\n 52 \r\n 53     def playbook_on_notify(self, host, handler):\r\n 54         pass\r\n 55 \r\n 56     def playbook_on_no_hosts_matched(self):\r\n 57         pass\r\n 58 \r\n 59     def playbook_on_no_hosts_remaining(self):\r\n 60         pass\r\n 61 \r\n 62     def playbook_on_task_start(self, name, is_conditional):\r\n 63         pass\r\n 64 \r\n 65     def playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):\r\n 66         pass\r\n 67 \r\n 68     def playbook_on_setup(self):\r\n 69         pass\r\n 70 \r\n 71     def playbook_on_import_for_host(self, host, imported_file):\r\n 72         ansible_logger.info('PLAYBOOK_ON_IMPORTED ' + host + ' ' + json.dumps(res, sort_keys=True))\r\n 73 \r\n 74     def playbook_on_not_import_for_host(self, host, missing_file):\r\n 75         ansible_logger.info('PLAYBOOK_ON_NOTIMPORTED ' + host + ' ' + json.dumps(res, sort_keys=True))\r\n 76 \r\n 77     def playbook_on_play_start(self, name):\r\n 78         pass\r\n 79 \r\n 80     def playbook_on_stats(self, stats):\r\n 81         pass\r\n```\r\nreplace localhost with your IP or add another handler to do remote logging (both locally and remotely)"}}