mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Transform both values of a task name into a byte str prior to comparing
Fixes #9571
This commit is contained in:
parent
a897a5ea89
commit
c4c3cc315d
4 changed files with 32 additions and 3 deletions
|
@ -603,11 +603,13 @@ class PlaybookCallbacks(object):
|
||||||
call_callback_module('playbook_on_no_hosts_remaining')
|
call_callback_module('playbook_on_no_hosts_remaining')
|
||||||
|
|
||||||
def on_task_start(self, name, is_conditional):
|
def on_task_start(self, name, is_conditional):
|
||||||
|
name = utils.to_bytes(name)
|
||||||
msg = "TASK: [%s]" % name
|
msg = "TASK: [%s]" % name
|
||||||
if is_conditional:
|
if is_conditional:
|
||||||
msg = "NOTIFIED: [%s]" % name
|
msg = "NOTIFIED: [%s]" % name
|
||||||
|
|
||||||
if hasattr(self, 'start_at'):
|
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):
|
if name == self.start_at or fnmatch.fnmatch(name, self.start_at):
|
||||||
# we found out match, we can get rid of this now
|
# we found out match, we can get rid of this now
|
||||||
del self.start_at
|
del self.start_at
|
||||||
|
|
|
@ -1265,13 +1265,24 @@ def make_su_cmd(su_user, executable, cmd):
|
||||||
)
|
)
|
||||||
return ('/bin/sh -c ' + pipes.quote(sudocmd), None, success_key)
|
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))
|
_TO_UNICODE_TYPES = (unicode, type(None))
|
||||||
|
|
||||||
def to_unicode(value):
|
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):
|
if isinstance(value, _TO_UNICODE_TYPES):
|
||||||
return value
|
return value
|
||||||
return value.decode("utf-8")
|
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):
|
def get_diff(diff):
|
||||||
# called by --diff usage in playbook and runner via callbacks
|
# called by --diff usage in playbook and runner via callbacks
|
||||||
|
|
|
@ -34,13 +34,12 @@ includes:
|
||||||
|
|
||||||
unicode:
|
unicode:
|
||||||
ansible-playbook unicode.yml -i $(INVENTORY) -e @$(VARS_FILE) -v $(TEST_FLAGS)
|
ansible-playbook unicode.yml -i $(INVENTORY) -e @$(VARS_FILE) -v $(TEST_FLAGS)
|
||||||
|
# Test the start-at-task flag #9571
|
||||||
|
ansible-playbook unicode.yml -i $(INVENTORY) -e @$(VARS_FILE) -v --start-at-task '*¶' -e 'start_at_task=True' $(TEST_FLAGS)
|
||||||
|
|
||||||
non_destructive:
|
non_destructive:
|
||||||
ansible-playbook non_destructive.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
ansible-playbook non_destructive.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
||||||
|
|
||||||
mine:
|
|
||||||
ansible-playbook mine.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
|
||||||
|
|
||||||
destructive:
|
destructive:
|
||||||
ansible-playbook destructive.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
ansible-playbook destructive.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
||||||
|
|
||||||
|
|
|
@ -41,3 +41,20 @@
|
||||||
tasks:
|
tasks:
|
||||||
- debug: msg='Unicode is a good thing ™'
|
- debug: msg='Unicode is a good thing ™'
|
||||||
- debug: msg=АБВГД
|
- debug: msg=АБВГД
|
||||||
|
|
||||||
|
# Run this test by adding to the CLI: -e start_at_task=True --start-at-task '*¶'
|
||||||
|
- name: 'Show that we can skip to unicode named tasks'
|
||||||
|
hosts: localhost
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
flag: 'original'
|
||||||
|
start_at_task: False
|
||||||
|
tasks:
|
||||||
|
- name: 'Override flag var'
|
||||||
|
set_fact: flag='new'
|
||||||
|
|
||||||
|
- name: 'A unicode task at the end of the playbook: ¶'
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'flag == "original"'
|
||||||
|
when: start_at_task|bool
|
||||||
|
|
Loading…
Reference in a new issue