mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-04 23:44:00 -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
|
@ -115,14 +115,17 @@ EXAMPLES = '''
|
|||
# sendgrid module support methods
|
||||
#
|
||||
import os
|
||||
import traceback
|
||||
|
||||
SENDGRID_IMP_ERR = None
|
||||
try:
|
||||
import sendgrid
|
||||
HAS_SENDGRID = True
|
||||
except ImportError:
|
||||
SENDGRID_IMP_ERR = traceback.format_exc()
|
||||
HAS_SENDGRID = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
@ -234,8 +237,10 @@ def main():
|
|||
sendgrid_lib_args = [api_key, bcc, cc, headers, from_name, html_body, attachments]
|
||||
|
||||
if any(lib_arg is not None for lib_arg in sendgrid_lib_args) and not HAS_SENDGRID:
|
||||
module.fail_json(msg='You must install the sendgrid python library if you want to use any of the following arguments: '
|
||||
'api_key, bcc, cc, headers, from_name, html_body, attachments')
|
||||
reason = 'when using any of the following arguments: ' \
|
||||
'api_key, bcc, cc, headers, from_name, html_body, attachments'
|
||||
module.fail_json(msg=missing_required_lib('sendgrid', reason=reason),
|
||||
exception=SENDGRID_IMP_ERR)
|
||||
|
||||
response, info = post_sendgrid_api(module, username, password,
|
||||
from_address, to_addresses, subject, body, attachments=attachments,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue