diff --git a/lookup_plugins/bitwarden.py b/lookup_plugins/bitwarden.py index 2e07b16..c02aac6 100755 --- a/lookup_plugins/bitwarden.py +++ b/lookup_plugins/bitwarden.py @@ -69,7 +69,7 @@ class Bitwarden(object): def __init__(self, path): self._cli_path = path try: - check_output(self._cli_path) + check_output([self._cli_path, "--version"]) except OSError: raise AnsibleError("Command not found: {0}".format(self._cli_path)) @@ -82,27 +82,28 @@ class Bitwarden(object): return 'BW_SESSION' in os.environ def _run(self, args): + print("%s %s" % (self.cli_path, args)) p = Popen([self.cli_path] + args, stdin=PIPE, stdout=PIPE, stderr=PIPE) out, err = p.communicate() rc = p.wait() if rc != 0: display.debug("Received error when running '{0} {1}': {2}" .format(self.cli_path, args, out)) - if out.startswith("Vault is locked."): + if err.startswith(b"Vault is locked."): raise AnsibleError("Error accessing Bitwarden vault. " "Run 'bw unlock' to unlock the vault.") - elif out.startswith("You are not logged in."): + elif err.startswith(b"You are not logged in."): raise AnsibleError("Error accessing Bitwarden vault. " "Run 'bw login' to login.") - elif out.startswith("Failed to decrypt."): + elif err.startswith(b"Failed to decrypt."): raise AnsibleError("Error accessing Bitwarden vault. " "Make sure BW_SESSION is set properly.") - elif out.startswith("Not found."): + elif err.startswith(b"Not found."): raise AnsibleError("Error accessing Bitwarden vault. " "Specified item not found.") else: raise AnsibleError("Unknown failure in 'bw' command: " - "{0}".format(out)) + "{0}".format(err)) return out.strip() def sync(self):