Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
85fb83a5
Commit
85fb83a5
authored
Oct 10, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1282 from dagwieers/mail-callback
Example plugin to send out mails on error
parents
ae94b050
bb58d3f2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
plugins/callbacks/mail.py
+83
-0
No files found.
plugins/callbacks/mail.py
0 → 100644
View file @
85fb83a5
# Copyright 2012 Dag Wieers <dag@wieers.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
smtplib
def
mail
(
subject
=
'Ansible error mail'
,
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
):
"""
This Ansible callback plugin mails errors to interested parties.
"""
def
runner_on_failed
(
self
,
host
,
res
,
ignore_errors
=
False
):
if
ignore_errors
:
return
sender
=
'Ansible error on
%
s'
%
host
subject
=
'Failure:
%
s'
%
res
[
'msg'
]
.
split
(
'
\n
'
)[
0
]
mail
(
sender
=
sender
,
subject
=
subject
,
body
=
'''The following task failed for host
%
s:
%
s
%
s
with the following error message:
%
s
A complete dump of the error:
%
s'''
%
(
host
,
res
[
'invocation'
][
'module_name'
],
res
[
'invocation'
][
'module_args'
],
res
[
'msg'
],
res
)
)
def
runner_on_error
(
self
,
host
,
msg
):
sender
=
'Ansible:
%
s <root>'
%
host
subject
=
'Error:
%
s'
%
res
[
'msg'
]
.
split
(
'
\n
'
)[
0
]
mail
(
sender
=
sender
,
subject
=
subject
,
body
=
msg
)
def
runner_on_unreachable
(
self
,
host
,
res
):
sender
=
'Ansible:
%
s <root>'
%
host
subject
=
'Unreachable:
%
s'
%
res
.
split
(
'
\n
'
)[
0
]
mail
(
sender
=
sender
,
subject
=
subject
,
body
=
res
)
def
runner_on_async_failed
(
self
,
host
,
res
,
jid
):
sender
=
'Ansible:
%
s <root>'
%
host
subject
=
'Async failure:
%
s'
%
res
.
split
(
'
\n
'
)[
0
]
mail
(
sender
=
sender
,
subject
=
subject
,
body
=
res
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment