[PR #9106/105ae056 backport][stable-9] bugfix - Prevent passwordstore lookup to create subkey when create == false (#9779)

bugfix - Prevent passwordstore lookup to create subkey when create == false (#9106)

Fixes #9105

Apply suggestion

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 105ae0566a)

Co-authored-by: Manuel Luzarreta <mluzarreta.pro@pm.me>
pull/9783/head
patchback[bot] 2025-02-19 22:30:22 +01:00 committed by GitHub
parent 1a0a44d179
commit 382c0a4af6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- passwordstore lookup plugin - fix subkey creation even when ``create=false`` (https://github.com/ansible-collections/community.general/issues/9105, https://github.com/ansible-collections/community.general/pull/9106).

View File

@ -578,11 +578,15 @@ class LookupModule(LookupBase):
for term in terms: for term in terms:
self.parse_params(term) # parse the input into paramvals self.parse_params(term) # parse the input into paramvals
with self.opt_lock('readwrite'): with self.opt_lock('readwrite'):
if self.check_pass(): # password exists if self.check_pass(): # password file exists
if self.paramvals['overwrite']: if self.paramvals['overwrite']: # if "overwrite", always update password
with self.opt_lock('write'): with self.opt_lock('write'):
result.append(self.update_password()) result.append(self.update_password())
elif self.paramvals["subkey"] != "password" and not self.passdict.get(self.paramvals['subkey']): # password exists but not the subkey elif (
self.paramvals["subkey"] != "password"
and not self.passdict.get(self.paramvals["subkey"])
and self.paramvals["missing"] == "create"
): # target is a subkey, this subkey is not in passdict BUT missing == create
with self.opt_lock('write'): with self.opt_lock('write'):
result.append(self.update_password()) result.append(self.update_password())
else: else: