|
|
@ -92,17 +92,40 @@ def present(dest, username, password, create, check_mode):
|
|
|
|
if check_mode:
|
|
|
|
if check_mode:
|
|
|
|
return ("Create %s" % dest, True)
|
|
|
|
return ("Create %s" % dest, True)
|
|
|
|
create_missing_directories(dest)
|
|
|
|
create_missing_directories(dest)
|
|
|
|
|
|
|
|
try:
|
|
|
|
ht = HtpasswdFile(dest, new=True)
|
|
|
|
ht = HtpasswdFile(dest, new=True)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
# library version doesn't take 'new', deal with it.
|
|
|
|
|
|
|
|
fh = open(dest, 'w')
|
|
|
|
|
|
|
|
fh.write('')
|
|
|
|
|
|
|
|
fh.close()
|
|
|
|
|
|
|
|
ht = HtpasswdFile(dest)
|
|
|
|
|
|
|
|
if getattr(ht, 'set_password', None):
|
|
|
|
ht.set_password(username, password)
|
|
|
|
ht.set_password(username, password)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
ht.update(username, password)
|
|
|
|
ht.save()
|
|
|
|
ht.save()
|
|
|
|
return ("Created %s and added %s" % (dest, username), True)
|
|
|
|
return ("Created %s and added %s" % (dest, username), True)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
try:
|
|
|
|
ht = HtpasswdFile(dest, new=False)
|
|
|
|
ht = HtpasswdFile(dest, new=False)
|
|
|
|
if ht.check_password(username, password):
|
|
|
|
except:
|
|
|
|
|
|
|
|
ht = HtpasswdFile(dest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
found = None
|
|
|
|
|
|
|
|
if getattr(ht, 'check_password', None):
|
|
|
|
|
|
|
|
found = ht.check_password(username, password)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
found = ht.verify(username, password)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if found:
|
|
|
|
return ("%s already present" % username, False)
|
|
|
|
return ("%s already present" % username, False)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if not check_mode:
|
|
|
|
if not check_mode:
|
|
|
|
|
|
|
|
if getattr(ht, 'set_password', None):
|
|
|
|
ht.set_password(username, password)
|
|
|
|
ht.set_password(username, password)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
ht.update(username, password)
|
|
|
|
ht.save()
|
|
|
|
ht.save()
|
|
|
|
return ("Add/update %s" % username, True)
|
|
|
|
return ("Add/update %s" % username, True)
|
|
|
|
|
|
|
|
|
|
|
@ -114,7 +137,11 @@ def absent(dest, username, check_mode):
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
if not os.path.exists(dest):
|
|
|
|
raise ValueError("%s does not exists" % dest)
|
|
|
|
raise ValueError("%s does not exists" % dest)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
ht = HtpasswdFile(dest, new=False)
|
|
|
|
ht = HtpasswdFile(dest, new=False)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
ht = HtpasswdFile(dest)
|
|
|
|
|
|
|
|
|
|
|
|
if username not in ht.users():
|
|
|
|
if username not in ht.users():
|
|
|
|
return ("%s not present" % username, False)
|
|
|
|
return ("%s not present" % username, False)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|