From 6d9f780937b4438a5e8f5a5353a61dcbca018527 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 20 Oct 2016 13:48:20 -0700 Subject: [PATCH] Now that we convert salt inside of do_encryptas needed, keep salt as text type until then. --- lib/ansible/plugins/lookup/password.py | 3 +-- lib/ansible/utils/encrypt.py | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ansible/plugins/lookup/password.py b/lib/ansible/plugins/lookup/password.py index 530fd2ea90f..bbc75e1145f 100644 --- a/lib/ansible/plugins/lookup/password.py +++ b/lib/ansible/plugins/lookup/password.py @@ -248,8 +248,7 @@ class LookupModule(LookupBase): _write_password_file(b_path, content) if params['encrypt']: - password = do_encrypt(plaintext_password, params['encrypt'], - salt=to_bytes(salt, encoding='ascii', errors='strict')) + password = do_encrypt(plaintext_password, params['encrypt'], salt=salt) ret.append(password) else: ret.append(plaintext_password) diff --git a/lib/ansible/utils/encrypt.py b/lib/ansible/utils/encrypt.py index c88387050df..ae36879278a 100644 --- a/lib/ansible/utils/encrypt.py +++ b/lib/ansible/utils/encrypt.py @@ -67,7 +67,7 @@ except ImportError: from ansible import constants as C from ansible.errors import AnsibleError -from ansible.module_utils._text import to_text, to_native +from ansible.module_utils._text import to_text, to_bytes __all__ = ['do_encrypt'] @@ -84,8 +84,10 @@ def do_encrypt(result, encrypt, salt_size=None, salt=None): if salt_size: result = crypt.encrypt(result, salt_size=salt_size) elif salt: - if not crypt._salt_is_bytes: - salt = to_native(salt) + if crypt._salt_is_bytes: + salt = to_bytes(salt, encoding='ascii', errors='strict') + else: + salt = to_text(salt, encoding='ascii', errors='strict') result = crypt.encrypt(result, salt=salt) else: result = crypt.encrypt(result)