From 1badcffe1c827ddad091b1502809de1af2e0225b Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 22:31:45 +0100 Subject: [PATCH] Clearer error logging in passwordstore lookup (#5436) (#5458) * Clearer error logging in passwordstore lookup * Add changelog fragment for passwordstore errmsgs Co-authored-by: Sylvia van Os (cherry picked from commit e4b9e098c74e405cae911d01d2561e208ff3421c) Co-authored-by: Jan-Philipp Litza --- changelogs/fragments/5436-passwordstore-errors.yml | 2 ++ plugins/lookup/passwordstore.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/5436-passwordstore-errors.yml diff --git a/changelogs/fragments/5436-passwordstore-errors.yml b/changelogs/fragments/5436-passwordstore-errors.yml new file mode 100644 index 00000000000..86c9e06b363 --- /dev/null +++ b/changelogs/fragments/5436-passwordstore-errors.yml @@ -0,0 +1,2 @@ +minor_changes: + - passwordstore lookup plugin - improve error messages to include stderr (https://github.com/ansible-collections/community.general/pull/5436) diff --git a/plugins/lookup/passwordstore.py b/plugins/lookup/passwordstore.py index ce1f4ee852a..0756d117910 100644 --- a/plugins/lookup/passwordstore.py +++ b/plugins/lookup/passwordstore.py @@ -268,7 +268,7 @@ def is_real_pass(self): ) self.realpass = 'pass: the standard unix password manager' in passoutput except (subprocess.CalledProcessError) as e: - raise AnsibleError(e) + raise AnsibleError('exit code {0} while running {1}. Error output: {2}'.format(e.returncode, e.cmd, e.output)) return self.realpass @@ -354,7 +354,7 @@ def check_pass(self): except (subprocess.CalledProcessError) as e: # 'not in password store' is the expected error if a password wasn't found if 'not in the password store' not in e.output: - raise AnsibleError(e) + raise AnsibleError('exit code {0} while running {1}. Error output: {2}'.format(e.returncode, e.cmd, e.output)) if self.paramvals['missing'] == 'error': raise AnsibleError('passwordstore: passname {0} not found and missing=error is set'.format(self.passname)) @@ -387,7 +387,7 @@ def update_password(self): try: check_output2([self.pass_cmd, 'insert', '-f', '-m', self.passname], input=msg, env=self.env) except (subprocess.CalledProcessError) as e: - raise AnsibleError(e) + raise AnsibleError('exit code {0} while running {1}. Error output: {2}'.format(e.returncode, e.cmd, e.output)) return newpass def generate_password(self): @@ -399,7 +399,7 @@ def generate_password(self): try: check_output2([self.pass_cmd, 'insert', '-f', '-m', self.passname], input=msg, env=self.env) except (subprocess.CalledProcessError) as e: - raise AnsibleError(e) + raise AnsibleError('exit code {0} while running {1}. Error output: {2}'.format(e.returncode, e.cmd, e.output)) return newpass def get_passresult(self):