|
|
|
@ -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,
|
|
|
|
|