mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
forgot finally 2.4 syntax
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user