diff options
author | Anders Ingemann <anders@ingemann.de> | 2016-06-07 04:17:23 +0200 |
---|---|---|
committer | Brian Coca <bcoca@ansible.com> | 2016-06-06 22:17:23 -0400 |
commit | 483c96681ebfc42345e3724ecba61cc061ad0035 (patch) | |
tree | dcdbfd494b07990034d2b81372bde192403f6b62 /monitoring | |
parent | 5d900b7a7766021dbf0ce88f0798c5f6267dea2d (diff) | |
download | ansible-modules-extras-483c96681ebfc42345e3724ecba61cc061ad0035.tar.gz |
Sensu subscription bugfixes (#2380)
* Fix syntax for exception catching
* Friendlier error message as per suggestion by @bcoca
Diffstat (limited to 'monitoring')
-rw-r--r-- | monitoring/sensu_subscription.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/monitoring/sensu_subscription.py b/monitoring/sensu_subscription.py index d845d72c..192b474e 100644 --- a/monitoring/sensu_subscription.py +++ b/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 |