Fix for when the password file did not exist previously
This commit is contained in:
parent
ed279d8175
commit
cb776e6190
1 changed files with 26 additions and 19 deletions
|
@ -78,6 +78,7 @@ EXAMPLES = """
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -199,28 +200,34 @@ def main():
|
||||||
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.
|
# Check file for blank lines in effort to avoid "need more than 1 value to unpack" error.
|
||||||
f = open(path, "r")
|
|
||||||
try:
|
try:
|
||||||
lines=f.readlines()
|
f = open(path, "r")
|
||||||
|
except IOError:
|
||||||
|
# No preexisting file to remove blank lines from
|
||||||
|
f = None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
lines = f.readlines()
|
||||||
finally:
|
finally:
|
||||||
f.close
|
f.close()
|
||||||
|
|
||||||
# If the file gets edited, it returns true, so only edit the file if it has blank lines
|
# If the file gets edited, it returns true, so only edit the file if it has blank lines
|
||||||
strip = False
|
strip = False
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if not line.strip():
|
if not line.strip():
|
||||||
strip = True
|
strip = True
|
||||||
|
break
|
||||||
|
|
||||||
if strip:
|
if strip:
|
||||||
# If check mode, create a temporary file
|
# If check mode, create a temporary file
|
||||||
if check_mode:
|
if check_mode:
|
||||||
temp = tempfile.NamedTemporaryFile()
|
temp = tempfile.NamedTemporaryFile()
|
||||||
path = temp.name
|
path = temp.name
|
||||||
f = open(path,"w")
|
f = open(path, "w")
|
||||||
try:
|
try:
|
||||||
[f.write(line) for line in lines if line.strip() ]
|
[ f.write(line) for line in lines if line.strip() ]
|
||||||
finally:
|
finally:
|
||||||
f.close
|
f.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
|
Loading…
Reference in a new issue