Description
ISSUE TYPE
- Bug Report
COMPONENT NAME
sendgrid
ANSIBLE VERSION
ansible 2.2.0.0
config file =
configured module search path = Default w/o overrides
CONFIGURATION
N/A
OS / ENVIRONMENT
Reproduced on OS X and CentOS 7. Believed to be platform independent.
SUMMARY
The sendgrid client library used by the Ansible module in v2.2 (and probably earlier) has made a number of breaking changes in the past calendar year: sendgrid/sendgrid-python#217
The module in v2.2 only works with versions of the library prior to v3.0. The latest is 3.6.3 as of this writing. If anyone does just a pip install sendgrid
they're going to get a library that will give them a stacktrace dump when they use the sendgrid module.
The workaround for now is to use pip install sendgrid==2.2.1
to get the latest version that is compatible with what ships in Ansible v2.2.
STEPS TO REPRODUCE
Run the following playbook.
---
- hosts: localhost
gather_facts: no
vars:
sendgrid_user: USER
sendgrid_pass: PAZZWERD
sendgrid_to_email: to@example.com
sendgrid_from_email: from@example.com
tasks:
- name: Email file
sendgrid:
username: "{{ sendgrid_user }}"
password: "{{ sendgrid_pass }}"
subject: "Test message"
body: |
This is a test message for sendgrid to send.<br>
<br>
It doesn't matter what it says as long as it sends it.<br>
to_addresses: "{{ sendgrid_to_email }}"
html_body: yes
from_address: "{{ sendgrid_from_email }}"
attachments:
- "hello.txt"
EXPECTED RESULTS
The task to succeed and the email to be sent.
ACTUAL RESULTS
The playbook fails and displays a stack trace.
TASK [Email file] **************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'module' object has no attribute 'SendGridClient'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n File \"/var/folders/v9/lkyh_wqj6szbhgk8whwxpfcr0000gn/T/ansible_PZz2CF/ansible_module_sendgrid.py\", line 271, in <module>\n main()\n File \"/var/folders/v9/lkyh_wqj6szbhgk8whwxpfcr0000gn/T/ansible_PZz2CF/ansible_module_sendgrid.py\", line 256, in main\n bcc=bcc, cc=cc, headers=headers, html_body=html_body, api_key=api_key)\n File \"/var/folders/v9/lkyh_wqj6szbhgk8whwxpfcr0000gn/T/ansible_PZz2CF/ansible_module_sendgrid.py\", line 172, in post_sendgrid_api\n sg = sendgrid.SendGridClient(username, password)\nAttributeError: 'module' object has no attribute 'SendGridClient'\n", "module_stdout": "", "msg": "MODULE FAILURE"}