mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
passwordstore: Add missing_subkey parameter (#8166)
* passwordstore: Add missing_subkey parameter Add ability to trigger error or warning when a subkey is missing in pass file. By default the behavior is unchanged (if subkey is missing, None is returned). This option can also be set in ansible.cfg * passwordstore - missing_subkey: Update changelog/fragments file with PR number * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
bafad8ecd4
commit
da29ea151d
2 changed files with 33 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- passwordstore lookup - add ``missing_subkey`` parameter defining the behavior of the lookup when a passwordstore subkey is missing (https://github.com/ansible-collections/community.general/pull/8166).
|
|
@ -139,6 +139,21 @@ DOCUMENTATION = '''
|
|||
type: bool
|
||||
default: true
|
||||
version_added: 8.1.0
|
||||
missing_subkey:
|
||||
description:
|
||||
- Preference about what to do if the password subkey is missing.
|
||||
- If set to V(error), the lookup will error out if the subkey does not exist.
|
||||
- If set to V(empty) or V(warn), will return a V(none) in case the subkey does not exist.
|
||||
version_added: 8.6.0
|
||||
type: str
|
||||
default: empty
|
||||
choices:
|
||||
- error
|
||||
- warn
|
||||
- empty
|
||||
ini:
|
||||
- section: passwordstore_lookup
|
||||
key: missing_subkey
|
||||
notes:
|
||||
- The lookup supports passing all options as lookup parameters since community.general 6.0.0.
|
||||
'''
|
||||
|
@ -147,6 +162,7 @@ ansible.cfg: |
|
|||
[passwordstore_lookup]
|
||||
lock=readwrite
|
||||
locktimeout=45s
|
||||
missing_subkey=warn
|
||||
|
||||
tasks.yml: |
|
||||
---
|
||||
|
@ -432,6 +448,20 @@ class LookupModule(LookupBase):
|
|||
if self.paramvals['subkey'] in self.passdict:
|
||||
return self.passdict[self.paramvals['subkey']]
|
||||
else:
|
||||
if self.paramvals["missing_subkey"] == "error":
|
||||
raise AnsibleError(
|
||||
"passwordstore: subkey {0} for passname {1} not found and missing_subkey=error is set".format(
|
||||
self.paramvals["subkey"], self.passname
|
||||
)
|
||||
)
|
||||
|
||||
if self.paramvals["missing_subkey"] == "warn":
|
||||
display.warning(
|
||||
"passwordstore: subkey {0} for passname {1} not found".format(
|
||||
self.paramvals["subkey"], self.passname
|
||||
)
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
@contextmanager
|
||||
|
@ -481,6 +511,7 @@ class LookupModule(LookupBase):
|
|||
'umask': self.get_option('umask'),
|
||||
'timestamp': self.get_option('timestamp'),
|
||||
'preserve': self.get_option('preserve'),
|
||||
"missing_subkey": self.get_option("missing_subkey"),
|
||||
}
|
||||
|
||||
def run(self, terms, variables, **kwargs):
|
||||
|
|
Loading…
Reference in a new issue