Sensu subscription bugfixes (#2380)
* Fix syntax for exception catching * Friendlier error message as per suggestion by @bcoca
This commit is contained in:
parent
5d900b7a77
commit
483c96681e
1 changed files with 5 additions and 3 deletions
|
@ -83,7 +83,8 @@ def sensu_subscription(module, path, name, state='present', backup=False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = json.load(open(path))
|
config = json.load(open(path))
|
||||||
except IOError, e:
|
except IOError:
|
||||||
|
e = get_exception()
|
||||||
if e.errno is 2: # File not found, non-fatal
|
if e.errno is 2: # File not found, non-fatal
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
reasons.append('file did not exist and state is `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)
|
module.backup_local(path)
|
||||||
try:
|
try:
|
||||||
open(path, 'w').write(json.dumps(config, indent=2) + '\n')
|
open(path, 'w').write(json.dumps(config, indent=2) + '\n')
|
||||||
except IOError, e:
|
except IOError:
|
||||||
module.fail_json(msg=str(e))
|
e = get_exception()
|
||||||
|
module.fail_json(msg='Failed to write to file %s: %s' % (path, str(e)))
|
||||||
|
|
||||||
return changed, reasons
|
return changed, reasons
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue