remove blank lines from htpasswd file
used standard mktemp()
This commit is contained in:
parent
758688a667
commit
c9d1cc0ce3
1 changed files with 24 additions and 0 deletions
|
@ -198,6 +198,30 @@ def main():
|
||||||
if not passlib_installed:
|
if not passlib_installed:
|
||||||
module.fail_json(msg="This module requires the passlib Python library")
|
module.fail_json(msg="This module requires the passlib Python library")
|
||||||
|
|
||||||
|
# Check file for blank lines in effort to avoid "need more than 1 value to unpack" error.
|
||||||
|
f = open(path, "r")
|
||||||
|
try:
|
||||||
|
lines=f.readlines()
|
||||||
|
finally:
|
||||||
|
f.close
|
||||||
|
|
||||||
|
# If the file gets edited, it returns true, so only edit the file if it has blank lines
|
||||||
|
strip = False
|
||||||
|
for line in lines:
|
||||||
|
if not line.strip():
|
||||||
|
strip = True
|
||||||
|
|
||||||
|
if strip:
|
||||||
|
# If check mode, create a temporary file
|
||||||
|
if check_mode:
|
||||||
|
temp = tempfile.NamedTemporaryFile()
|
||||||
|
path = temp.name
|
||||||
|
f = open(path,"w")
|
||||||
|
try:
|
||||||
|
[f.write(line) for line in lines if line.strip() ]
|
||||||
|
finally:
|
||||||
|
f.close
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
(msg, changed) = present(path, username, password, crypt_scheme, create, check_mode)
|
(msg, changed) = present(path, username, password, crypt_scheme, create, check_mode)
|
||||||
|
|
Loading…
Reference in a new issue