mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add crypt scheme to htpasswd params
This commit is contained in:
parent
7e849ac7e0
commit
a47f2674a4
1 changed files with 14 additions and 7 deletions
|
@ -40,6 +40,11 @@ options:
|
|||
description:
|
||||
- Password associated with user.
|
||||
- Must be specified if user does not exist yet
|
||||
crypt_scheme:
|
||||
required: false
|
||||
default: "apr_md5_crypt"
|
||||
description:
|
||||
- Encryption scheme to be used. One of: "apr_md5_crypt", "des_crypt", "ldap_sha1" or "plaintext"
|
||||
state:
|
||||
required: false
|
||||
choices: [ present, absent ]
|
||||
|
@ -82,7 +87,7 @@ def create_missing_directories(dest):
|
|||
os.makedirs(destpath)
|
||||
|
||||
|
||||
def present(dest, username, password, create, check_mode):
|
||||
def present(dest, username, password, crypt_scheme, create, check_mode):
|
||||
""" Ensures user is present
|
||||
|
||||
Returns (msg, changed) """
|
||||
|
@ -93,13 +98,13 @@ def present(dest, username, password, create, check_mode):
|
|||
return ("Create %s" % dest, True)
|
||||
create_missing_directories(dest)
|
||||
try:
|
||||
ht = HtpasswdFile(dest, new=True)
|
||||
ht = HtpasswdFile(dest, new=True, default_scheme=crypt_scheme)
|
||||
except:
|
||||
# library version doesn't take 'new', deal with it.
|
||||
fh = open(dest, 'w')
|
||||
fh.write('')
|
||||
fh.close()
|
||||
ht = HtpasswdFile(dest)
|
||||
ht = HtpasswdFile(dest, default_scheme=crypt_scheme)
|
||||
if getattr(ht, 'set_password', None):
|
||||
ht.set_password(username, password)
|
||||
else:
|
||||
|
@ -108,10 +113,10 @@ def present(dest, username, password, create, check_mode):
|
|||
return ("Created %s and added %s" % (dest, username), True)
|
||||
else:
|
||||
try:
|
||||
ht = HtpasswdFile(dest, new=False)
|
||||
ht = HtpasswdFile(dest, new=False, default_scheme=crypt_scheme)
|
||||
except:
|
||||
ht = HtpasswdFile(dest)
|
||||
|
||||
ht = HtpasswdFile(dest, default_scheme=crypt_scheme)
|
||||
|
||||
found = None
|
||||
if getattr(ht, 'check_password', None):
|
||||
found = ht.check_password(username, password)
|
||||
|
@ -169,6 +174,7 @@ def main():
|
|||
path=dict(required=True, aliases=["dest", "destfile"]),
|
||||
name=dict(required=True, aliases=["username"]),
|
||||
password=dict(required=False, default=None),
|
||||
crypt_scheme=dict(required=False, default=None),
|
||||
state=dict(required=False, default="present"),
|
||||
create=dict(type='bool', choices=BOOLEANS, default='yes'),
|
||||
|
||||
|
@ -180,6 +186,7 @@ def main():
|
|||
path = module.params['path']
|
||||
username = module.params['name']
|
||||
password = module.params['password']
|
||||
crypt_scheme = module.params['crypt_scheme']
|
||||
state = module.params['state']
|
||||
create = module.params['create']
|
||||
check_mode = module.check_mode
|
||||
|
@ -189,7 +196,7 @@ def main():
|
|||
|
||||
try:
|
||||
if state == 'present':
|
||||
(msg, changed) = present(path, username, password, create, check_mode)
|
||||
(msg, changed) = present(path, username, password, crypt_scheme, create, check_mode)
|
||||
elif state == 'absent':
|
||||
(msg, changed) = absent(path, username, check_mode)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue