From 7144a8889786f6ceafc1ff3639708d540a6f91a9 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Tue, 7 Jun 2016 04:17:23 +0200 Subject: [PATCH] Sensu subscription bugfixes (#2380) * Fix syntax for exception catching * Friendlier error message as per suggestion by @bcoca --- .../modules/extras/monitoring/sensu_subscription.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/extras/monitoring/sensu_subscription.py b/lib/ansible/modules/extras/monitoring/sensu_subscription.py index d845d72c9d5..192b474ee48 100644 --- a/lib/ansible/modules/extras/monitoring/sensu_subscription.py +++ b/lib/ansible/modules/extras/monitoring/sensu_subscription.py @@ -83,7 +83,8 @@ def sensu_subscription(module, path, name, state='present', backup=False): try: config = json.load(open(path)) - except IOError, e: + except IOError: + e = get_exception() if e.errno is 2: # File not found, non-fatal if state == 'absent': reasons.append('file did not exist and state is `absent\'') @@ -129,8 +130,9 @@ def sensu_subscription(module, path, name, state='present', backup=False): module.backup_local(path) try: open(path, 'w').write(json.dumps(config, indent=2) + '\n') - except IOError, e: - module.fail_json(msg=str(e)) + except IOError: + e = get_exception() + module.fail_json(msg='Failed to write to file %s: %s' % (path, str(e))) return changed, reasons