I have been learning from this book Fabio Alessandro Locati, published under Packt>. The example can be found at https://github.com/PacktPublishing/Learning-Ansible-2.X-Third-Edition/tree/master/Chapter06
Today I am learning about working with notification. One of the biggest advantages of Ansible is its ability, compared to a bash script to notify. The 6 tools which Ansible could easily work with include
- Email Notification
- Ansible XMPP/Jabber
- Slack and Rocket Chat
- Sending a message to an IRC Channel
- Amazon Simple Notification Service
- Nagios
For the full list of notification modules, we can refer to https://docs.ansible.com/ansible/2.8/modules/list_of_notification_modules.html
Email:
---
- hosts: localhost
connection: local
tasks:
- name: Read the machine uptime
command: uptime -p
register: uptime
- name: Send the uptime via e-mail
mail:
host: mail.fale.io
username: ansible@fale.io
password: PASSWORD
to: me@fale.io
subject: Ansible-report
body: 'Local system uptime is {{ uptime.stdout }}.'
To sent the email, we will need the SMTP host, credential and content of the email. Do note that mail modules support the following
- The attachment parameter: To attach attachments
- The port parameter: port to use by the email server.