Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A callback plugin that logs failure message #96

Merged
merged 1 commit into from Aug 5, 2015

Conversation

andrewschoen
Copy link
Contributor

This callback plugin is called on every failure and prints out the
failure information as yaml so that it's easier to read in the
teuthology logs.

If the environment variable ANSIBLE_FAILURE_LOG is present then a log of
all failures in the playbook will be persisted to the file
path given in the ANSIBLE_FAILURE_LOG.

Signed-off-by: Andrew Schoen aschoen@redhat.com

@andrewschoen
Copy link
Contributor Author

Produces output like this:

TASK: [debug msg="I'll always fail"] ******************************************
failed: [XXX.ceph.redhat.com] => {"failed": true, "failed_when_result": true, "verbose_always": true}
msg: I'll always fail

****Ansible Failure******

XXX.ceph.redhat.com:
  failed: true
  failed_when_result: true
  invocation: {module_args: msg="I'll always fail", module_name: debug}
  msg: I'll always fail
  verbose_always: true

@@ -3,3 +3,4 @@ ansible_managed = This file is managed by ansible, don't make changes here - the
# this works when testing from my laptop, but will need to
# be changed when it lives in a production environment
vault_password_file = ~/.vault_pass.txt
callback_plugins = ~/.ansible/plugins/callback_plugins/:/usr/share/ansible_plugins/callback_plugins:./library/plugins/callback
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why three items here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the other two are the default values and I didn't want to lose those

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Maybe a comment would be a good idea here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.


def log_failure(host, result):
"""
Print any failures to stdout nicely formatted as yaml.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything here that sends output to stdout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, just changed that behavior but forgot to update the docs.

@andrewschoen andrewschoen force-pushed the wip-ansible-failures-module branch 2 times, most recently from 5ec51a0 to 1b8786b Compare August 4, 2015 19:28
@andrewschoen andrewschoen changed the title A callback plugin that logs failure message DNM: A callback plugin that logs failure message Aug 4, 2015
@andrewschoen
Copy link
Contributor Author

I've changed this to DNM until I've got this working on the teuthology side as well.

@andrewschoen andrewschoen force-pushed the wip-ansible-failures-module branch 2 times, most recently from 483268f to bd4e383 Compare August 5, 2015 15:25
@andrewschoen andrewschoen changed the title DNM: A callback plugin that logs failure message A callback plugin that logs failure message Aug 5, 2015
@andrewschoen
Copy link
Contributor Author

This has been tested with teuthology and is working correctly. My first attempt was not thread safe when multiple nodes were involved, but using the logging module fixes that.

Teuthology PR: ceph/teuthology#589

the file path given in ANSIBLE_FAILURE_LOG.
"""
failure = {"{0}".format(host): dict()}
failure[host] = result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these two lines be inside the if clause below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They could be, yeah. I don't think it would affect the functionality at all though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, just wasted effort if no logging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've moved those two lines inside the if statement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just less (albeit small) overhead when we're not actually using the feature

If the environment variable ANSIBLE_FAILURE_LOG is present then a log of
all failures in the playbook will be persisted to the file
path given in the ANSIBLE_FAILURE_LOG.

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
zmc added a commit that referenced this pull request Aug 5, 2015
A callback plugin that logs failure message
@zmc zmc merged commit b3d947d into master Aug 5, 2015
@zmc zmc deleted the wip-ansible-failures-module branch August 5, 2015 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants