Ansible: Email Notification

From Glitchdata
Jump to navigation Jump to search

When scripting notification via email, the email can be send via:

  1. The Local Machine
  2. The Remote Machine


Local Machine

# Example playbook sending mail to root
- local_action: mail subject='System {{ ansible_hostname }} has been successfully provisioned.'

# Sending an e-mail using Gmail SMTP servers
- local_action: mail
                host='smtp.gmail.com'
                port=587
                username=username@gmail.com
                password='mysecret'
                to="John Smith <john.smith@example.com>"
                subject='Ansible-report'
                body='System {{ ansible_hostname }} has been successfully provisioned.'

# Send e-mail to a bunch of users, attaching files
- local_action: mail
                host='127.0.0.1'
                port=2025
                subject="Ansible-report"
                body="Hello, this is an e-mail. I hope you like it ;-)"
                from="jane@example.net (Jane Jolie)"
                to="John Doe <j.d@example.org>, Suzie Something <sue@example.com>"
                cc="Charlie Root <root@localhost>"
                attach="/etc/group /tmp/pavatar2.png"
                headers=Reply-To=john@example.com|X-Special="Something or other"
                charset=utf8


Remote Machine

# Sending an e-mail using the remote machine, not the Ansible controller node
- mail:
    host='localhost'
    port=25
    to="John Smith <john.smith@example.com>"
    subject='Ansible-report'
    body='System {{ ansible_hostname }} has been successfully provisioned.'


Challenges

  • mail server authentication


Links