Transform both values of a task name into a byte str prior to comparing

Fixes #9571
This commit is contained in:
Toshio Kuratomi
2014-11-19 11:50:02 -08:00
parent a897a5ea89
commit c4c3cc315d
4 changed files with 32 additions and 3 deletions

View File

@@ -603,11 +603,13 @@ class PlaybookCallbacks(object):
call_callback_module('playbook_on_no_hosts_remaining')
def on_task_start(self, name, is_conditional):
name = utils.to_bytes(name)
msg = "TASK: [%s]" % name
if is_conditional:
msg = "NOTIFIED: [%s]" % name
if hasattr(self, 'start_at'):
self.start_at = utils.to_bytes(self.start_at)
if name == self.start_at or fnmatch.fnmatch(name, self.start_at):
# we found out match, we can get rid of this now
del self.start_at

View File

@@ -1265,13 +1265,24 @@ def make_su_cmd(su_user, executable, cmd):
)
return ('/bin/sh -c ' + pipes.quote(sudocmd), None, success_key)
# For v2, consider either using kitchen or copying my code from there for
# to_unicode and to_bytes handling (TEK)
_TO_UNICODE_TYPES = (unicode, type(None))
def to_unicode(value):
# Use with caution -- this function is not encoding safe (non-utf-8 values
# will cause tracebacks if they contain bytes from 0x80-0xff inclusive)
if isinstance(value, _TO_UNICODE_TYPES):
return value
return value.decode("utf-8")
def to_bytes(value):
# Note: value is assumed to be a basestring to mirror to_unicode. Better
# implementations (like kitchen.text.converters.to_bytes) bring that check
# into the function
if isinstance(value, str):
return value
return value.encode('utf-8')
def get_diff(diff):
# called by --diff usage in playbook and runner via callbacks