mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-30 04:49:09 -07:00
Use common functions for handling import errors (#51851)
* Use common functions for handling import errors * use refactored version of gitlab modules
This commit is contained in:
parent
28dcfa985f
commit
c1e51ef486
39 changed files with 233 additions and 93 deletions
|
@ -72,11 +72,15 @@ EXAMPLES = '''
|
|||
|
||||
RETURN = '''
|
||||
'''
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
import traceback
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
MATRIX_IMP_ERR = None
|
||||
try:
|
||||
from matrix_client.client import MatrixClient
|
||||
except ImportError:
|
||||
MATRIX_IMP_ERR = traceback.format_exc()
|
||||
matrix_found = False
|
||||
else:
|
||||
matrix_found = True
|
||||
|
@ -107,7 +111,7 @@ def run_module():
|
|||
)
|
||||
|
||||
if not matrix_found:
|
||||
module.fail_json(msg="Python 'matrix-client' module is required. Install via: $ pip install matrix-client")
|
||||
module.fail_json(msg=missing_required_lib('matrix-client'), exception=MATRIX_IMP_ERR)
|
||||
|
||||
if module.check_mode:
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue