From a17b664b3872cb543e91eb0cf9bdb6aba85398a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Tue, 8 Jan 2019 11:39:54 +0100 Subject: [PATCH] Fix lastpass lookup error Fixes #42062. (cherry picked from commit 15fb9d3bc0284c3e6d928242789cfad7d9ab3046) --- changelogs/fragments/50540-fix-lastpass-lookup-error.yaml | 2 ++ lib/ansible/plugins/lookup/lastpass.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/50540-fix-lastpass-lookup-error.yaml diff --git a/changelogs/fragments/50540-fix-lastpass-lookup-error.yaml b/changelogs/fragments/50540-fix-lastpass-lookup-error.yaml new file mode 100644 index 00000000000..3fa38c2cd4e --- /dev/null +++ b/changelogs/fragments/50540-fix-lastpass-lookup-error.yaml @@ -0,0 +1,2 @@ +bugfixes: + - "fix lastpass lookup failure on python 3 (https://github.com/ansible/ansible/issues/42062)" diff --git a/lib/ansible/plugins/lookup/lastpass.py b/lib/ansible/plugins/lookup/lastpass.py index 1faf9df5a91..02df58e3b5b 100644 --- a/lib/ansible/plugins/lookup/lastpass.py +++ b/lib/ansible/plugins/lookup/lastpass.py @@ -38,6 +38,7 @@ RETURN = """ from subprocess import Popen, PIPE from ansible.errors import AnsibleError +from ansible.module_utils._text import to_bytes, to_text from ansible.plugins.lookup import LookupBase @@ -61,11 +62,11 @@ class LPass(object): def _run(self, args, stdin=None, expected_rc=0): p = Popen([self.cli_path] + args, stdout=PIPE, stderr=PIPE, stdin=PIPE) - out, err = p.communicate(stdin) + out, err = p.communicate(to_bytes(stdin)) rc = p.wait() if rc != expected_rc: raise LPassException(err) - return out, err + return to_text(out, errors='surrogate_or_strict'), to_text(err, errors='surrogate_or_strict') def _build_args(self, command, args=None): if args is None: