Coverage for lib/ansible/plugins/callback/log_plays.py : 45%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# (C) 2012, Michael DeHaan, <michael.dehaan@gmail.com> # (c) 2017 Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
callback: log_plays type: notification short_description: write playbook output to log file version_added: historical description: - This callback writes playbook output to a file per host in the `/var/log/ansible/hosts` directory - "TODO: make this configurable" requirements: - Whitelist in configuration - A writeable /var/log/ansible/hosts directory by the user executing Ansible on the controller '''
# NOTE: in Ansible 1.2 or later general logging is available without # this plugin, just set ANSIBLE_LOG_PATH as an environment variable # or log_path in the DEFAULTS section of your ansible configuration # file. This callback is an example of per hosts logging for those # that want it.
""" logs playbook results, per host, in /var/log/ansible/hosts """
super(CallbackModule, self).__init__()
if not os.path.exists("/var/log/ansible/hosts"): os.makedirs("/var/log/ansible/hosts")
if isinstance(data, MutableMapping): if '_ansible_verbose_override' in data: # avoid logging extraneous data data = 'omitted' else: data = data.copy() invocation = data.pop('invocation', None) data = json.dumps(data) if invocation is not None: data = json.dumps(invocation) + " => %s " % data
path = os.path.join("/var/log/ansible/hosts", host) now = time.strftime(self.TIME_FORMAT, time.localtime())
msg = to_bytes(self.MSG_FORMAT % dict(now=now, category=category, data=data)) with open(path, "ab") as fd: fd.write(msg)
self.log(host, 'FAILED', res)
self.log(host, 'OK', res)
self.log(host, 'SKIPPED', '...')
self.log(host, 'UNREACHABLE', res)
self.log(host, 'ASYNC_FAILED', res)
self.log(host, 'IMPORTED', imported_file)
self.log(host, 'NOTIMPORTED', missing_file) |