Merge branch 'add-scheme-to-htpasswd-params' of https://github.com/PugglePay/ansible into PugglePay-add-scheme-to-htpasswd-params

reviewable/pr18780/r1
James Cammarata 11 years ago
commit 920bef12a3

@ -40,6 +40,11 @@ options:
description: description:
- Password associated with user. - Password associated with user.
- Must be specified if user does not exist yet - 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: state:
required: false required: false
choices: [ present, absent ] choices: [ present, absent ]
@ -82,7 +87,7 @@ def create_missing_directories(dest):
os.makedirs(destpath) 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 """ Ensures user is present
Returns (msg, changed) """ Returns (msg, changed) """
@ -93,13 +98,13 @@ def present(dest, username, password, create, check_mode):
return ("Create %s" % dest, True) return ("Create %s" % dest, True)
create_missing_directories(dest) create_missing_directories(dest)
try: try:
ht = HtpasswdFile(dest, new=True) ht = HtpasswdFile(dest, new=True, default_scheme=crypt_scheme)
except: except:
# library version doesn't take 'new', deal with it. # library version doesn't take 'new', deal with it.
fh = open(dest, 'w') fh = open(dest, 'w')
fh.write('') fh.write('')
fh.close() fh.close()
ht = HtpasswdFile(dest) ht = HtpasswdFile(dest, default_scheme=crypt_scheme)
if getattr(ht, 'set_password', None): if getattr(ht, 'set_password', None):
ht.set_password(username, password) ht.set_password(username, password)
else: else:
@ -108,9 +113,9 @@ def present(dest, username, password, create, check_mode):
return ("Created %s and added %s" % (dest, username), True) return ("Created %s and added %s" % (dest, username), True)
else: else:
try: try:
ht = HtpasswdFile(dest, new=False) ht = HtpasswdFile(dest, new=False, default_scheme=crypt_scheme)
except: except:
ht = HtpasswdFile(dest) ht = HtpasswdFile(dest, default_scheme=crypt_scheme)
found = None found = None
if getattr(ht, 'check_password', None): if getattr(ht, 'check_password', None):
@ -169,6 +174,7 @@ def main():
path=dict(required=True, aliases=["dest", "destfile"]), path=dict(required=True, aliases=["dest", "destfile"]),
name=dict(required=True, aliases=["username"]), name=dict(required=True, aliases=["username"]),
password=dict(required=False, default=None), password=dict(required=False, default=None),
crypt_scheme=dict(required=False, default=None),
state=dict(required=False, default="present"), state=dict(required=False, default="present"),
create=dict(type='bool', choices=BOOLEANS, default='yes'), create=dict(type='bool', choices=BOOLEANS, default='yes'),
@ -180,6 +186,7 @@ def main():
path = module.params['path'] path = module.params['path']
username = module.params['name'] username = module.params['name']
password = module.params['password'] password = module.params['password']
crypt_scheme = module.params['crypt_scheme']
state = module.params['state'] state = module.params['state']
create = module.params['create'] create = module.params['create']
check_mode = module.check_mode check_mode = module.check_mode
@ -189,7 +196,7 @@ def main():
try: try:
if state == 'present': 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': elif state == 'absent':
(msg, changed) = absent(path, username, check_mode) (msg, changed) = absent(path, username, check_mode)
else: else:

Loading…
Cancel
Save