Skip to content

Commit

Permalink
Clearer error logging in passwordstore lookup (#5436) (#5458)
Browse files Browse the repository at this point in the history
* Clearer error logging in passwordstore lookup

* Add changelog fragment for passwordstore errmsgs

Co-authored-by: Sylvia van Os <[email protected]>
(cherry picked from commit e4b9e09)

Co-authored-by: Jan-Philipp Litza <[email protected]>
  • Loading branch information
patchback[bot] and jplitza authored Nov 2, 2022
1 parent b871963 commit 1badcff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/5436-passwordstore-errors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- passwordstore lookup plugin - improve error messages to include stderr (https://github.com/ansible-collections/community.general/pull/5436)
8 changes: 4 additions & 4 deletions plugins/lookup/passwordstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 1badcff

Please sign in to comment.