forgot finally 2.4 syntax
This commit is contained in:
parent
bfa63e01e5
commit
a4a17630cd
1 changed files with 19 additions and 17 deletions
|
@ -183,19 +183,20 @@ def sensu_check(module, path, name, state='present', backup=False):
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stream = open(path, 'r')
|
try:
|
||||||
config = json.load(stream.read())
|
stream = open(path, 'r')
|
||||||
except IOError, e:
|
config = json.load(stream.read())
|
||||||
if e.errno is 2: # File not found, non-fatal
|
except IOError, e:
|
||||||
if state == 'absent':
|
if e.errno is 2: # File not found, non-fatal
|
||||||
reasons.append('file did not exist and state is `absent\'')
|
if state == 'absent':
|
||||||
return changed, reasons
|
reasons.append('file did not exist and state is `absent\'')
|
||||||
config = {}
|
return changed, reasons
|
||||||
else:
|
config = {}
|
||||||
module.fail_json(msg=str(e))
|
else:
|
||||||
except ValueError:
|
module.fail_json(msg=str(e))
|
||||||
msg = '{path} contains invalid JSON'.format(path=path)
|
except ValueError:
|
||||||
module.fail_json(msg=msg)
|
msg = '{path} contains invalid JSON'.format(path=path)
|
||||||
|
module.fail_json(msg=msg)
|
||||||
finally:
|
finally:
|
||||||
if stream:
|
if stream:
|
||||||
stream.close()
|
stream.close()
|
||||||
|
@ -277,10 +278,11 @@ def sensu_check(module, path, name, state='present', backup=False):
|
||||||
if backup:
|
if backup:
|
||||||
module.backup_local(path)
|
module.backup_local(path)
|
||||||
try:
|
try:
|
||||||
stream = open(path, 'w')
|
try:
|
||||||
stream.write(json.dumps(config, indent=2) + '\n')
|
stream = open(path, 'w')
|
||||||
except IOError, e:
|
stream.write(json.dumps(config, indent=2) + '\n')
|
||||||
module.fail_json(msg=str(e))
|
except IOError, e:
|
||||||
|
module.fail_json(msg=str(e))
|
||||||
finally:
|
finally:
|
||||||
if stream:
|
if stream:
|
||||||
stream.close()
|
stream.close()
|
||||||
|
|
Loading…
Reference in a new issue