Skip to content

Instantly share code, notes, and snippets.

@sivel
Created March 20, 2015 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivel/105347f6df18691446b0 to your computer and use it in GitHub Desktop.
Save sivel/105347f6df18691446b0 to your computer and use it in GitHub Desktop.
email-cmd.py ansible callback plugin
import os
import sys
import smtplib
def mail(subject='Ansible Command', sender='<root>', to='root', cc=None,
bcc=None, body=None):
if not body:
body = subject
smtp = smtplib.SMTP('localhost')
content = 'From: %s\n' % sender
content += 'To: %s\n' % to
if cc:
content += 'Cc: %s\n' % cc
content += 'Subject: %s\n\n' % subject
content += body
addresses = to.split(',')
if cc:
addresses += cc.split(',')
if bcc:
addresses += bcc.split(',')
for address in addresses:
smtp.sendmail(sender, address, content)
smtp.quit()
class CallbackModule(object):
def playbook_on_stats(self, stats):
sys.argv[0] = os.path.basename(sys.argv[0])
mail(to='matt@sivel.net', body=' '.join(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment