From 74a10d7ca2329117bbb00a122a256f3df50179bd Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 1 Dec 2016 23:42:43 -0800 Subject: [PATCH] Transform vault_pass into text when we read it in from the user or a file. (#18699) Fixes #18684 --- lib/ansible/cli/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index 84cc99132f..6574f9fb42 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -173,7 +173,7 @@ class CLI(with_metaclass(ABCMeta, object)): # enforce no newline chars at the end of passwords if vault_pass: - vault_pass = to_bytes(vault_pass, errors='strict', nonstring='simplerepr').strip() + vault_pass = to_text(vault_pass, errors='surrogate_or_strict', nonstring='simplerepr').strip() return vault_pass @@ -189,7 +189,7 @@ class CLI(with_metaclass(ABCMeta, object)): pass if new_vault_pass: - new_vault_pass = to_bytes(new_vault_pass, errors='strict', nonstring='simplerepr').strip() + new_vault_pass = to_text(new_vault_pass, errors='surrogate_or_strict', nonstring='simplerepr').strip() return new_vault_pass @@ -630,7 +630,7 @@ class CLI(with_metaclass(ABCMeta, object)): stdout, stderr = p.communicate() if p.returncode != 0: raise AnsibleError("Vault password script %s returned non-zero (%s): %s" % (this_path, p.returncode, p.stderr)) - vault_pass = stdout.strip('\r\n') + vault_pass = stdout.strip(b'\r\n') else: try: f = open(this_path, "rb") @@ -639,7 +639,7 @@ class CLI(with_metaclass(ABCMeta, object)): except (OSError, IOError) as e: raise AnsibleError("Could not read vault password file %s: %s" % (this_path, e)) - return vault_pass + return to_text(vault_pass, errors='surrogate_or_strict') def get_opt(self, k, defval=""): """