On this page
sendgrid - Sends an email with the SendGrid API
New in version 2.0.
Synopsis
- Sends an email with a SendGrid account through their API, not through the SMTP service.
Requirements (on host that executes module)
- sendgrid python library
Options
parameter | required | default | choices | comments |
---|---|---|---|---|
api_key
(added in 2.2)
|
no |
sendgrid API key to use instead of username/password
|
||
attachments
(added in 2.2)
|
no |
a list of relative or explicit paths of files you want to attach (7MB limit as per SendGrid docs)
|
||
bcc
(added in 2.2)
|
no |
a list of email addresses to bcc
|
||
cc
(added in 2.2)
|
no |
a list of email addresses to cc
|
||
from_address |
yes |
the address in the "from" field for the email
|
||
from_name
(added in 2.2)
|
no |
the name you want to appear in the from field, i.e 'John Doe'
|
||
headers
(added in 2.2)
|
no |
a dict to pass on as headers
|
||
html_body
(added in 2.2)
|
no |
whether the body is html content that should be rendered
|
||
password |
no |
password that corresponds to the username
Since 2.2 it is only required if api_key is not supplied.
|
||
subject |
yes |
the desired subject for the email
|
||
to_addresses |
yes |
a list with one or more recipient email addresses
|
||
username |
no |
username for logging into the SendGrid account.
Since 2.2 it is only required if api_key is not supplied.
|
Examples
# send an email to a single recipient that the deployment was successful
- sendgrid:
username: "{{ sendgrid_username }}"
password: "{{ sendgrid_password }}"
from_address: "ansible@mycompany.com"
to_addresses:
- "ops@mycompany.com"
subject: "Deployment success."
body: "The most recent Ansible deployment was successful."
delegate_to: localhost
# send an email to more than one recipient that the build failed
- sendgrid:
username: "{{ sendgrid_username }}"
password: "{{ sendgrid_password }}"
from_address: "build@mycompany.com"
to_addresses:
- "ops@mycompany.com"
- "devteam@mycompany.com"
subject: "Build failure!."
body: "Unable to pull source repository from Git server."
delegate_to: localhost
Notes
Note
- This module is non-idempotent because it sends an email through the external API. It is idempotent only in the case that the module fails.
- Like the other notification modules, this one requires an external dependency to work. In this case, you’ll need an active SendGrid account.
- In order to use api_key, cc, bcc, attachments, from_name, html_body, headers you must pip install sendgrid
- since 2.2 username and password are not required if you supply an api_key
Status
This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.
For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.4/sendgrid_module.html