Skip to content

Commit 06e5463

Browse files
committed
Add details of module internal errors in event body
Handles the changes brought by Ansible 2
1 parent a535a04 commit 06e5463

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

datadog_callback.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,15 @@ def format_result(res):
155155
elif not res.get('invocation'):
156156
event_text = msg
157157
else:
158-
event_text = "$$$\n{0}[{1}]\n$$$\n".format(res['invocation']['module_name'], res['invocation'].get('module_args', ''))
158+
invocation = res['invocation']
159+
event_text = "$$$\n{0}[{1}]\n$$$\n".format(invocation['module_name'], invocation.get('module_args', ''))
159160
event_text += msg
160-
module_name = 'module:{0}'.format(res['invocation']['module_name'])
161+
module_name = 'module:{0}'.format(invocation['module_name'])
162+
if 'module_stdout' in res:
163+
# On Ansible v2, details on internal failures of modules are not reported in the `msg`,
164+
# so we have to extract the info differently
165+
event_text += "$$$\n{0}\n{1}\n$$$\n".format(
166+
res.get('module_stdout', ''), res.get('module_stderr', ''))
161167

162168
return event_text, module_name
163169

0 commit comments

Comments
 (0)