summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2015-06-23 13:32:02 -0400
committerJames Cammarata <jimi@sngx.net>2015-06-23 13:32:02 -0400
commita1181b490b7e00953a954878f3694a32378deca4 (patch)
tree0eb2c3bad2f319c03da93cb8969351c807a4694e
parentab31a14c0a51371667ec3531f0f7bdd27d4201e6 (diff)
parent41049042de1fc302f05d668b58617a6d2b26a2ea (diff)
downloadansible-modules-core-a1181b490b7e00953a954878f3694a32378deca4.tar.gz
Merge pull request #1406 from Jmainguy/htpasswd_blank
remove blank lines from htpasswd file
-rw-r--r--web_infrastructure/htpasswd.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/web_infrastructure/htpasswd.py b/web_infrastructure/htpasswd.py
index fce8b062..274f8fa3 100644
--- a/web_infrastructure/htpasswd.py
+++ b/web_infrastructure/htpasswd.py
@@ -198,6 +198,30 @@ def main():
if not passlib_installed:
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:
if state == 'present':
(msg, changed) = present(path, username, password, crypt_scheme, create, check_mode)