* Transform vars_prompt result to unicode type before returning (Fixes #10319)

* Rename prompt method as do_prompt to avoid potential bug when logging via a callback plugin
pull/10324/head
Toshio Kuratomi 10 years ago
parent db91ab35e7
commit a6fbd83660

@ -28,6 +28,7 @@ import constants
import locale import locale
from ansible.color import stringc from ansible.color import stringc
from ansible.module_utils import basic from ansible.module_utils import basic
from ansible.utils.unicode import to_unicode
import logging import logging
if constants.DEFAULT_LOG_PATH != '': if constants.DEFAULT_LOG_PATH != '':
@ -661,7 +662,7 @@ class PlaybookCallbacks(object):
else: else:
msg = 'input for %s: ' % varname msg = 'input for %s: ' % varname
def prompt(prompt, private): def do_prompt(prompt, private):
if sys.stdout.encoding: if sys.stdout.encoding:
msg = prompt.encode(sys.stdout.encoding) msg = prompt.encode(sys.stdout.encoding)
else: else:
@ -676,13 +677,13 @@ class PlaybookCallbacks(object):
if confirm: if confirm:
while True: while True:
result = prompt(msg, private) result = do_prompt(msg, private)
second = prompt("confirm " + msg, private) second = do_prompt("confirm " + msg, private)
if result == second: if result == second:
break break
display("***** VALUES ENTERED DO NOT MATCH ****") display("***** VALUES ENTERED DO NOT MATCH ****")
else: else:
result = prompt(msg, private) result = do_prompt(msg, private)
# if result is false and default is not None # if result is false and default is not None
if not result and default is not None: if not result and default is not None:
@ -690,8 +691,10 @@ class PlaybookCallbacks(object):
if encrypt: if encrypt:
result = utils.do_encrypt(result,encrypt,salt_size,salt) result = utils.do_encrypt(result, encrypt, salt_size, salt)
# handle utf-8 chars
result = to_unicode(result, error='strict')
call_callback_module( 'playbook_on_vars_prompt', varname, private=private, prompt=prompt, call_callback_module( 'playbook_on_vars_prompt', varname, private=private, prompt=prompt,
encrypt=encrypt, confirm=confirm, salt_size=salt_size, salt=None, default=default encrypt=encrypt, confirm=confirm, salt_size=salt_size, salt=None, default=default
) )

Loading…
Cancel
Save