mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Make password lookup treat /dev/null as a special case
I have from time to time a need of random password without wanting to write them down (one example is mailman list creation, that requires a password to be given to be sent to the list owner). But using /dev/null do not return null, but the empty string, which doesn't generate a password at all and so do not achieve my use case.
This commit is contained in:
parent
103ede26df
commit
6fae1d2bbf
3 changed files with 18 additions and 2 deletions
|
@ -232,7 +232,8 @@ class LookupModule(LookupBase):
|
|||
|
||||
changed = False
|
||||
content = _read_password_file(b_path)
|
||||
if content is None:
|
||||
|
||||
if content is None or b_path == to_bytes('/dev/null'):
|
||||
plaintext_password = _random_password(params['length'], chars)
|
||||
salt = None
|
||||
changed = True
|
||||
|
@ -243,7 +244,7 @@ class LookupModule(LookupBase):
|
|||
changed = True
|
||||
salt = _random_salt()
|
||||
|
||||
if changed:
|
||||
if changed and b_path != to_bytes('/dev/null'):
|
||||
content = _format_content(plaintext_password, salt, encrypt=params['encrypt'])
|
||||
_write_password_file(b_path, content)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue