Skip to content

Commit 9039a70

Browse files
committed
Catch exceptions the ansible way
1 parent c1ad9e8 commit 9039a70

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

library/commvault.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@
199199
'''
200200

201201
from ansible.module_utils.basic import AnsibleModule
202+
from ansible.module_utils._text import to_text
202203
from cvpysdk.commcell import Commcell
204+
from cvpysdk.exception import SDKException
203205
from cvpysdk.job import Job
204206

205207

@@ -331,9 +333,12 @@ def main():
331333
else:
332334
if module.params.get('args'):
333335
statement = '{0} = list(module.params["args"].values())[0]'.format(statement)
334-
exec(statement)
335-
result['output'] = "Property set successfully"
336-
module.exit_json(**result)
336+
try:
337+
_ = exec(statement)
338+
result['output'] = "Property set successfully"
339+
module.exit_json(**result)
340+
except SDKException as sdk_exception:
341+
module.fail_json(to_text(sdk_exception))
337342

338343
output = eval(statement)
339344

0 commit comments

Comments
 (0)