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
55366bdc
Commit
55366bdc
authored
Jul 08, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ported mail callback plugin to work with v2
parent
897e098b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
20 deletions
+43
-20
lib/ansible/plugins/callback/mail.py
+43
-20
No files found.
plugins/callbacks
/mail.py
→
lib/ansible/plugins/callback
/mail.py
View file @
55366bdc
...
...
@@ -15,13 +15,23 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
os
import
smtplib
from
ansible.plugins.callback
import
CallbackBase
def
mail
(
subject
=
'Ansible error mail'
,
sender
=
'<root>'
,
to
=
'root'
,
cc
=
None
,
bcc
=
None
,
body
=
None
):
if
not
body
:
def
mail
(
subject
=
'Ansible error mail'
,
sender
=
None
,
to
=
None
,
cc
=
None
,
bcc
=
None
,
body
=
None
,
smtphost
=
None
):
if
sender
is
None
:
sender
=
'<root>'
if
to
is
None
:
to
=
'root'
if
smtphost
is
None
:
smtphost
=
os
.
getenv
(
'SMTPHOST'
,
'localhost'
)
if
body
is
None
:
body
=
subject
smtp
=
smtplib
.
SMTP
(
'localhost'
)
smtp
=
smtplib
.
SMTP
(
smtphost
)
content
=
'From:
%
s
\n
'
%
sender
content
+=
'To:
%
s
\n
'
%
to
...
...
@@ -42,31 +52,40 @@ def mail(subject='Ansible error mail', sender='<root>', to='root', cc=None, bcc=
smtp
.
quit
()
class
CallbackModule
(
object
):
class
CallbackModule
(
CallbackBase
):
"""
This Ansible callback plugin mails errors to interested parties.
"""
CALLBACK_VERSION
=
2.0
CALLBACK_TYPE
=
'notification'
def
v2_runner_on_failed
(
self
,
res
,
ignore_errors
=
False
):
host
=
res
.
_host
.
get_name
()
def
runner_on_failed
(
self
,
host
,
res
,
ignore_errors
=
False
):
if
ignore_errors
:
return
sender
=
'"Ansible:
%
s" <root>'
%
host
subject
=
'Failed:
%(module_name)
s
%(module_args)
s'
%
res
[
'invocation'
]
body
=
'The following task failed for host '
+
host
+
':
\n\n
%(module_name)
s
%(module_args)
s
\n\n
'
%
res
[
'invocation'
]
if
'stdout'
in
res
.
keys
()
and
res
[
'stdout'
]:
subject
=
res
[
'stdout'
]
.
strip
(
'
\r\n
'
)
.
split
(
'
\n
'
)[
-
1
]
body
+=
'with the following output in standard output:
\n\n
'
+
res
[
'stdout'
]
+
'
\n\n
'
if
'stderr'
in
res
.
keys
()
and
res
[
'stderr'
]:
subject
=
'Failed:
%
s'
%
(
res
.
_task
.
action
)
body
=
'The following task failed for host '
+
host
+
':
\n\n
%
s
\n\n
'
%
(
res
.
_task
.
action
)
if
'stdout'
in
res
.
_result
.
keys
()
and
res
.
_result
[
'stdout'
]:
subject
=
res
.
_result
[
'stdout'
]
.
strip
(
'
\r\n
'
)
.
split
(
'
\n
'
)[
-
1
]
body
+=
'with the following output in standard output:
\n\n
'
+
res
.
_result
[
'stdout'
]
+
'
\n\n
'
if
'stderr'
in
res
.
_result
.
keys
()
and
res
.
_result
[
'stderr'
]:
subject
=
res
[
'stderr'
]
.
strip
(
'
\r\n
'
)
.
split
(
'
\n
'
)[
-
1
]
body
+=
'with the following output in standard error:
\n\n
'
+
res
[
'stderr'
]
+
'
\n\n
'
if
'msg'
in
res
.
keys
()
and
res
[
'msg'
]:
subject
=
res
[
'msg'
]
.
strip
(
'
\r\n
'
)
.
split
(
'
\n
'
)[
0
]
body
+=
'with the following message:
\n\n
'
+
res
[
'msg'
]
+
'
\n\n
'
body
+=
'A complete dump of the error:
\n\n
'
+
str
(
res
)
body
+=
'with the following output in standard error:
\n\n
'
+
res
.
_result
[
'stderr'
]
+
'
\n\n
'
if
'msg'
in
res
.
_result
.
keys
()
and
res
.
_result
[
'msg'
]:
subject
=
res
.
_result
[
'msg'
]
.
strip
(
'
\r\n
'
)
.
split
(
'
\n
'
)[
0
]
body
+=
'with the following message:
\n\n
'
+
res
.
_result
[
'msg'
]
+
'
\n\n
'
body
+=
'A complete dump of the error:
\n\n
'
+
str
(
res
.
_result
[
'msg'
]
)
mail
(
sender
=
sender
,
subject
=
subject
,
body
=
body
)
def
runner_on_unreachable
(
self
,
host
,
res
):
def
v2_runner_on_unreachable
(
self
,
ressult
):
host
=
result
.
_host
.
get_name
()
res
=
result
.
_result
sender
=
'"Ansible:
%
s" <root>'
%
host
if
isinstance
(
res
,
basestring
):
subject
=
'Unreachable:
%
s'
%
res
.
strip
(
'
\r\n
'
)
.
split
(
'
\n
'
)[
-
1
]
...
...
@@ -77,7 +96,11 @@ class CallbackModule(object):
res
[
'msg'
]
+
'
\n\n
A complete dump of the error:
\n\n
'
+
str
(
res
)
mail
(
sender
=
sender
,
subject
=
subject
,
body
=
body
)
def
runner_on_async_failed
(
self
,
host
,
res
,
jid
):
def
v2_runner_on_async_failed
(
self
,
result
):
host
=
result
.
_host
.
get_name
()
res
=
result
.
_result
sender
=
'"Ansible:
%
s" <root>'
%
host
if
isinstance
(
res
,
basestring
):
subject
=
'Async failure:
%
s'
%
res
.
strip
(
'
\r\n
'
)
.
split
(
'
\n
'
)[
-
1
]
...
...
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