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
1274ce56
Commit
1274ce56
authored
Jul 11, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added result sanitation to registered var and to callbacks
removed time display as it only is provided by command module
parent
fdea0088
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
19 deletions
+31
-19
lib/ansible/constants.py
+1
-0
lib/ansible/executor/process/result.py
+3
-1
lib/ansible/plugins/callback/__init__.py
+15
-0
lib/ansible/plugins/callback/default.py
+4
-8
lib/ansible/plugins/callback/mail.py
+1
-1
lib/ansible/plugins/callback/minimal.py
+1
-3
lib/ansible/plugins/callback/syslog_json.py
+6
-6
No files found.
lib/ansible/constants.py
View file @
1274ce56
...
@@ -235,3 +235,4 @@ DEFAULT_SUBSET = None
...
@@ -235,3 +235,4 @@ DEFAULT_SUBSET = None
DEFAULT_SU_PASS
=
None
DEFAULT_SU_PASS
=
None
VAULT_VERSION_MIN
=
1.0
VAULT_VERSION_MIN
=
1.0
VAULT_VERSION_MAX
=
1.0
VAULT_VERSION_MAX
=
1.0
RESULT_SANITIZE
=
frozenset
([
'invocation'
,
'warnings'
])
lib/ansible/executor/process/result.py
View file @
1274ce56
...
@@ -33,6 +33,7 @@ try:
...
@@ -33,6 +33,7 @@ try:
except
ImportError
:
except
ImportError
:
HAS_ATFORK
=
False
HAS_ATFORK
=
False
from
ansible
import
constants
as
C
from
ansible.playbook.handler
import
Handler
from
ansible.playbook.handler
import
Handler
from
ansible.playbook.task
import
Task
from
ansible.playbook.task
import
Task
...
@@ -107,7 +108,8 @@ class ResultProcess(multiprocessing.Process):
...
@@ -107,7 +108,8 @@ class ResultProcess(multiprocessing.Process):
# if this task is registering a result, do it now
# if this task is registering a result, do it now
if
result
.
_task
.
register
:
if
result
.
_task
.
register
:
self
.
_send_result
((
'register_host_var'
,
result
.
_host
,
result
.
_task
.
register
,
result
.
_result
))
res
=
{
k
:
result
.
_result
[
k
]
for
k
in
set
(
result
.
_result
.
keys
())
.
difference
(
C
.
RESULT_SANITIZE
)}
self
.
_send_result
((
'register_host_var'
,
result
.
_host
,
result
.
_task
.
register
,
res
))
# send callbacks, execute other options based on the result status
# send callbacks, execute other options based on the result status
# FIXME: this should all be cleaned up and probably moved to a sub-function.
# FIXME: this should all be cleaned up and probably moved to a sub-function.
...
...
lib/ansible/plugins/callback/__init__.py
View file @
1274ce56
...
@@ -19,8 +19,13 @@
...
@@ -19,8 +19,13 @@
from
__future__
import
(
absolute_import
,
division
)
from
__future__
import
(
absolute_import
,
division
)
__metaclass__
=
type
__metaclass__
=
type
import
json
from
ansible
import
constants
as
C
__all__
=
[
"CallbackBase"
]
__all__
=
[
"CallbackBase"
]
class
CallbackBase
:
class
CallbackBase
:
'''
'''
...
@@ -40,6 +45,16 @@ class CallbackBase:
...
@@ -40,6 +45,16 @@ class CallbackBase:
version
=
getattr
(
self
,
'CALLBACK_VERSION'
,
'unknwon'
)
version
=
getattr
(
self
,
'CALLBACK_VERSION'
,
'unknwon'
)
self
.
_display
.
vvvv
(
'Loaded callback
%
s of type
%
s, v
%
s'
%
(
name
,
ctype
,
version
))
self
.
_display
.
vvvv
(
'Loaded callback
%
s of type
%
s, v
%
s'
%
(
name
,
ctype
,
version
))
def
_dump_results
(
self
,
result
,
sanitize
=
True
,
indent
=
4
,
sort_keys
=
True
):
if
sanitize
:
res
=
self
.
_sanitize_result
(
result
)
else
:
res
=
results
return
json
.
dumps
(
res
,
indent
=
indent
,
ensure_ascii
=
False
,
sort_keys
=
sort_keys
)
def
_sanitize_result
(
self
,
result
):
return
{
k
:
result
[
k
]
for
k
in
set
(
result
.
keys
())
.
difference
(
C
.
RESULT_SANITIZE
)}
def
set_connection_info
(
self
,
conn_info
):
def
set_connection_info
(
self
,
conn_info
):
pass
pass
...
...
lib/ansible/plugins/callback/default.py
View file @
1274ce56
...
@@ -19,8 +19,6 @@
...
@@ -19,8 +19,6 @@
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
__metaclass__
=
type
import
json
from
ansible.plugins.callback
import
CallbackBase
from
ansible.plugins.callback
import
CallbackBase
class
CallbackModule
(
CallbackBase
):
class
CallbackModule
(
CallbackBase
):
...
@@ -48,7 +46,7 @@ class CallbackModule(CallbackBase):
...
@@ -48,7 +46,7 @@ class CallbackModule(CallbackBase):
# finally, remove the exception from the result so it's not shown every time
# finally, remove the exception from the result so it's not shown every time
del
result
.
_result
[
'exception'
]
del
result
.
_result
[
'exception'
]
self
.
_display
.
display
(
"fatal: [
%
s]: FAILED! =>
%
s"
%
(
result
.
_host
.
get_name
(),
json
.
dumps
(
result
.
_result
,
ensure_ascii
=
False
)),
color
=
'red'
)
self
.
_display
.
display
(
"fatal: [
%
s]: FAILED! =>
%
s"
%
(
result
.
_host
.
get_name
(),
self
.
_dump_results
(
result
.
_result
)),
color
=
'red'
)
if
result
.
_task
.
ignore_errors
:
if
result
.
_task
.
ignore_errors
:
self
.
_display
.
display
(
"...ignoring"
)
self
.
_display
.
display
(
"...ignoring"
)
...
@@ -70,9 +68,7 @@ class CallbackModule(CallbackBase):
...
@@ -70,9 +68,7 @@ class CallbackModule(CallbackBase):
if
'verbose_always'
in
result
.
_result
:
if
'verbose_always'
in
result
.
_result
:
indent
=
4
indent
=
4
del
result
.
_result
[
'verbose_always'
]
del
result
.
_result
[
'verbose_always'
]
if
self
.
_display
.
verbosity
>=
2
and
'delta'
in
result
.
_result
:
msg
+=
" =>
%
s"
%
self
.
_dump_results
(
result
.
_result
,
indent
=
indent
)
msg
+=
" [time:
%
s]"
%
(
result
.
_result
[
'delta'
])
msg
+=
" =>
%
s"
%
json
.
dumps
(
result
.
_result
,
indent
=
indent
,
ensure_ascii
=
False
)
self
.
_display
.
display
(
msg
,
color
=
color
)
self
.
_display
.
display
(
msg
,
color
=
color
)
def
v2_runner_on_skipped
(
self
,
result
):
def
v2_runner_on_skipped
(
self
,
result
):
...
@@ -82,11 +78,11 @@ class CallbackModule(CallbackBase):
...
@@ -82,11 +78,11 @@ class CallbackModule(CallbackBase):
if
'verbose_always'
in
result
.
_result
:
if
'verbose_always'
in
result
.
_result
:
indent
=
4
indent
=
4
del
result
.
_result
[
'verbose_always'
]
del
result
.
_result
[
'verbose_always'
]
msg
+=
" =>
%
s"
%
json
.
dumps
(
result
.
_result
,
indent
=
indent
,
ensure_ascii
=
False
)
msg
+=
" =>
%
s"
%
self
.
_dump_results
(
result
.
_result
,
indent
=
indent
)
self
.
_display
.
display
(
msg
,
color
=
'cyan'
)
self
.
_display
.
display
(
msg
,
color
=
'cyan'
)
def
v2_runner_on_unreachable
(
self
,
result
):
def
v2_runner_on_unreachable
(
self
,
result
):
self
.
_display
.
display
(
"fatal: [
%
s]: UNREACHABLE! =>
%
s"
%
(
result
.
_host
.
get_name
(),
result
.
_result
),
color
=
'red'
)
self
.
_display
.
display
(
"fatal: [
%
s]: UNREACHABLE! =>
%
s"
%
(
result
.
_host
.
get_name
(),
self
.
_dump_results
(
result
.
_result
)
),
color
=
'red'
)
def
v2_playbook_on_no_hosts_matched
(
self
):
def
v2_playbook_on_no_hosts_matched
(
self
):
self
.
_display
.
display
(
"skipping: no hosts matched"
,
color
=
'cyan'
)
self
.
_display
.
display
(
"skipping: no hosts matched"
,
color
=
'cyan'
)
...
...
lib/ansible/plugins/callback/mail.py
View file @
1274ce56
...
@@ -82,7 +82,7 @@ class CallbackModule(CallbackBase):
...
@@ -82,7 +82,7 @@ class CallbackModule(CallbackBase):
if
'msg'
in
res
.
_result
.
keys
()
and
res
.
_result
[
'msg'
]:
if
'msg'
in
res
.
_result
.
keys
()
and
res
.
_result
[
'msg'
]:
subject
=
res
.
_result
[
'msg'
]
.
strip
(
'
\r\n
'
)
.
split
(
'
\n
'
)[
0
]
subject
=
res
.
_result
[
'msg'
]
.
strip
(
'
\r\n
'
)
.
split
(
'
\n
'
)[
0
]
body
+=
'with the following message:
\n\n
'
+
res
.
_result
[
'msg'
]
+
'
\n\n
'
body
+=
'with the following message:
\n\n
'
+
res
.
_result
[
'msg'
]
+
'
\n\n
'
body
+=
'A complete dump of the error:
\n\n
'
+
json
.
dumps
(
res
.
_result
,
indent
=
4
)
body
+=
'A complete dump of the error:
\n\n
'
+
self
.
_dump_results
(
res
.
_result
)
mail
(
sender
=
sender
,
subject
=
subject
,
body
=
body
)
mail
(
sender
=
sender
,
subject
=
subject
,
body
=
body
)
def
v2_runner_on_unreachable
(
self
,
result
):
def
v2_runner_on_unreachable
(
self
,
result
):
...
...
lib/ansible/plugins/callback/minimal.py
View file @
1274ce56
...
@@ -19,8 +19,6 @@
...
@@ -19,8 +19,6 @@
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
__metaclass__
=
type
import
json
from
ansible.plugins.callback
import
CallbackBase
from
ansible.plugins.callback
import
CallbackBase
...
@@ -55,7 +53,7 @@ class CallbackModule(CallbackBase):
...
@@ -55,7 +53,7 @@ class CallbackModule(CallbackBase):
self
.
_display
.
display
(
"
%
s | FAILED! =>
%
s"
%
(
result
.
_host
.
get_name
(),
result
.
_result
),
color
=
'red'
)
self
.
_display
.
display
(
"
%
s | FAILED! =>
%
s"
%
(
result
.
_host
.
get_name
(),
result
.
_result
),
color
=
'red'
)
def
v2_runner_on_ok
(
self
,
result
):
def
v2_runner_on_ok
(
self
,
result
):
self
.
_display
.
display
(
"
%
s | SUCCESS =>
%
s"
%
(
result
.
_host
.
get_name
(),
json
.
dumps
(
result
.
_result
,
indent
=
4
)),
color
=
'green'
)
self
.
_display
.
display
(
"
%
s | SUCCESS =>
%
s"
%
(
result
.
_host
.
get_name
(),
self
.
_dump_results
(
result
.
_result
)),
color
=
'green'
)
def
v2_runner_on_skipped
(
self
,
result
):
def
v2_runner_on_skipped
(
self
,
result
):
pass
pass
...
...
lib/ansible/plugins/callback/syslog_json.py
View file @
1274ce56
...
@@ -40,22 +40,22 @@ class CallbackModule(CallbackBase):
...
@@ -40,22 +40,22 @@ class CallbackModule(CallbackBase):
def
runner_on_failed
(
self
,
host
,
res
,
ignore_errors
=
False
):
def
runner_on_failed
(
self
,
host
,
res
,
ignore_errors
=
False
):
self
.
logger
.
error
(
'
%
s ansible-command: task execution FAILED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
json
.
dumps
(
res
,
sort_keys
=
True
)))
self
.
logger
.
error
(
'
%
s ansible-command: task execution FAILED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
self
.
_dump_results
(
res
)))
def
runner_on_ok
(
self
,
host
,
res
):
def
runner_on_ok
(
self
,
host
,
res
):
self
.
logger
.
info
(
'
%
s ansible-command: task execution OK; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
json
.
dumps
(
res
,
sort_keys
=
True
)))
self
.
logger
.
info
(
'
%
s ansible-command: task execution OK; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
self
.
_dump_results
(
res
)))
def
runner_on_skipped
(
self
,
host
,
item
=
None
):
def
runner_on_skipped
(
self
,
host
,
item
=
None
):
self
.
logger
.
info
(
'
%
s ansible-command: task execution SKIPPED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
'skipped'
))
self
.
logger
.
info
(
'
%
s ansible-command: task execution SKIPPED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
'skipped'
))
def
runner_on_unreachable
(
self
,
host
,
res
):
def
runner_on_unreachable
(
self
,
host
,
res
):
self
.
logger
.
error
(
'
%
s ansible-command: task execution UNREACHABLE; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
json
.
dumps
(
res
,
sort_keys
=
True
)))
self
.
logger
.
error
(
'
%
s ansible-command: task execution UNREACHABLE; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
self
.
_dump_results
(
res
)))
def
runner_on_async_failed
(
self
,
host
,
res
):
def
runner_on_async_failed
(
self
,
host
,
res
):
self
.
logger
.
error
(
'
%
s ansible-command: task execution FAILED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
json
.
dumps
(
res
,
sort_keys
=
True
)))
self
.
logger
.
error
(
'
%
s ansible-command: task execution FAILED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
self
.
_dump_results
(
res
)))
def
playbook_on_import_for_host
(
self
,
host
,
imported_file
):
def
playbook_on_import_for_host
(
self
,
host
,
imported_file
):
self
.
logger
.
info
(
'
%
s ansible-command: playbook IMPORTED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
json
.
dumps
(
res
,
sort_keys
=
True
)))
self
.
logger
.
info
(
'
%
s ansible-command: playbook IMPORTED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
self
.
_dump_results
(
res
)))
def
playbook_on_not_import_for_host
(
self
,
host
,
missing_file
):
def
playbook_on_not_import_for_host
(
self
,
host
,
missing_file
):
self
.
logger
.
info
(
'
%
s ansible-command: playbook NOT IMPORTED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
json
.
dumps
(
res
,
sort_keys
=
True
)))
self
.
logger
.
info
(
'
%
s ansible-command: playbook NOT IMPORTED; host:
%
s; message:
%
s'
%
(
self
.
hostname
,
host
,
self
.
_dump_results
(
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