Created
March 20, 2015 00:07
-
-
Save sivel/105347f6df18691446b0 to your computer and use it in GitHub Desktop.
email-cmd.py ansible callback plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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