From 9ba597ac1eff72ed4718d3d7a420933af5da6ef5 Mon Sep 17 00:00:00 2001 From: Olivier Vielpeau Date: Thu, 1 Oct 2015 16:34:00 -0400 Subject: [PATCH] Fix KeyError on `res` argument passed to `runner_on_ok` Use a more conservative approach as to the existence of the `changed` key. This could be extended to all the keys that are used on dicts passed to the callback (as afaik Ansible doesn't provide any guarantee of their existence), but for now a case-by-case approach may be enough. --- datadog_callback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datadog_callback.py b/datadog_callback.py index 9d27ce7..c9694c0 100644 --- a/datadog_callback.py +++ b/datadog_callback.py @@ -124,7 +124,7 @@ def runner_on_failed(self, host, res, ignore_errors=False): def runner_on_ok(self, host, res): # Only send an event when the task has changed on the host - if res['changed']: + if res.get('changed'): event_text = "$$$\n{0}[{1}]\n$$$\n".format(res['invocation']['module_name'], res['invocation']['module_args']) self.send_task_event( 'Ansible task changed on "{0}"'.format(host),