community.general.sendgrid module – Sends an email with the SendGrid API
Note
This module is part of the community.general collection (version 8.6.4).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.general
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.general.sendgrid
.
Synopsis
Sends an email with a SendGrid account through their API, not through the SMTP service.
Aliases: notification.sendgrid
Requirements
The below requirements are needed on the host that executes this module.
sendgrid Python library 1.6.22 or lower (Sendgrid API V2 supported)
Parameters
Parameter |
Comments |
---|---|
Sendgrid API key to use instead of username/password. |
|
A list of relative or explicit paths of files you want to attach (7MB limit as per SendGrid docs). |
|
A list of email addresses to bcc. |
|
The e-mail body content. |
|
A list of email addresses to cc. |
|
The address in the “from” field for the email. |
|
The name you want to appear in the from field, i.e ‘John Doe’. |
|
A dict to pass on as headers. |
|
Whether the body is html content that should be rendered. Choices:
|
|
Password that corresponds to the username. It is only required if |
|
The desired subject for the email. |
|
A list with one or more recipient email addresses. |
|
Username for logging into the SendGrid account. It is only required if |
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in |
|
Support: none |
Will return details on what has changed (or possibly needs changing in |
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
Examples
- name: Send an email to a single recipient that the deployment was successful
community.general.sendgrid:
username: "{{ sendgrid_username }}"
password: "{{ sendgrid_password }}"
from_address: "[email protected]"
to_addresses:
- "[email protected]"
subject: "Deployment success."
body: "The most recent Ansible deployment was successful."
delegate_to: localhost
- name: Send an email to more than one recipient that the build failed
community.general.sendgrid:
username: "{{ sendgrid_username }}"
password: "{{ sendgrid_password }}"
from_address: "[email protected]"
to_addresses:
- "[email protected]"
- "[email protected]"
subject: "Build failure!."
body: "Unable to pull source repository from Git server."
delegate_to: localhost