Skip to content

Commit 105ae05

Browse files
bugfix - Prevent passwordstore lookup to create subkey when create == false (#9106)
Fixes #9105 Apply suggestion Co-authored-by: Felix Fontein <[email protected]>
1 parent 8e36fd4 commit 105ae05

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- 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).

plugins/lookup/passwordstore.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,20 @@ def run(self, terms, variables, **kwargs):
572572
for term in terms:
573573
self.parse_params(term) # parse the input into paramvals
574574
with self.opt_lock('readwrite'):
575-
if self.check_pass(): # password exists
576-
if self.paramvals['overwrite']:
575+
if self.check_pass(): # password file exists
576+
if self.paramvals['overwrite']: # if "overwrite", always update password
577577
with self.opt_lock('write'):
578578
result.append(self.update_password())
579-
elif self.paramvals["subkey"] != "password" and not self.passdict.get(self.paramvals['subkey']): # password exists but not the subkey
579+
elif (
580+
self.paramvals["subkey"] != "password"
581+
and not self.passdict.get(self.paramvals["subkey"])
582+
and self.paramvals["missing"] == "create"
583+
): # target is a subkey, this subkey is not in passdict BUT missing == create
580584
with self.opt_lock('write'):
581585
result.append(self.update_password())
582586
else:
583587
result.append(self.get_passresult())
584-
else: # password does not exist
588+
else: # password does not exist
585589
if self.paramvals['missing'] == 'create':
586590
with self.opt_lock('write'):
587591
if self.locked == 'write' and self.check_pass(): # lookup password again if under write lock

0 commit comments

Comments
 (0)