From: Andrew Schoen Date: Wed, 5 Aug 2015 15:17:21 +0000 (-0500) Subject: wip; use logger instead of yaml file X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f226cc40df4d85c6867c355a548c8a7cece012b4;p=ceph-cm-ansible.git wip; use logger instead of yaml file Signed-off-by: Andrew Schoen --- diff --git a/callback_plugins/failure_log.py b/callback_plugins/failure_log.py index 4fcb5b39..a57914e9 100644 --- a/callback_plugins/failure_log.py +++ b/callback_plugins/failure_log.py @@ -3,12 +3,14 @@ import os import logging log = logging.getLogger(__name__) +fail_log = os.environ.get('ANSIBLE_FAILURE_LOG') +if fail_log: + handler = logging.FileHandler(filename=fail_log) + log.addHandler(handler) def log_failure(host, result): """ - Print any failures to stdout nicely formatted as yaml. - If the environment variable ANSIBLE_FAILURE_LOG is present a log of all failures in the playbook will be persisted to the file path given in ANSIBLE_FAILURE_LOG. @@ -16,18 +18,8 @@ def log_failure(host, result): failure = {"{0}".format(host): dict()} failure[host] = result - fail_log = os.environ.get('ANSIBLE_FAILURE_LOG') if fail_log: - existing_failures = dict() - if os.path.exists(fail_log): - with open(fail_log, 'r') as outfile: - existing_failures = yaml.safe_load(outfile.read()) - - if existing_failures: - failure.update(existing_failures) - - with open(fail_log, 'w') as outfile: - outfile.write(yaml.safe_dump(failure)) + log.error(yaml.safe_dump(failure)) class CallbackModule(object):