Fixes #6482 Check sysctl file path and catch read exceptions
This commit is contained in:
parent
0c70cc123e
commit
59fb47ae9a
1 changed files with 10 additions and 1 deletions
|
@ -235,7 +235,16 @@ class SysctlModule(object):
|
||||||
|
|
||||||
# Get the token value from the sysctl file
|
# Get the token value from the sysctl file
|
||||||
def read_sysctl_file(self):
|
def read_sysctl_file(self):
|
||||||
lines = open(self.sysctl_file, "r").readlines()
|
|
||||||
|
lines = []
|
||||||
|
if os.path.isfile(self.sysctl_file):
|
||||||
|
try:
|
||||||
|
f = open(self.sysctl_file, "r")
|
||||||
|
lines = f.readlines()
|
||||||
|
f.close()
|
||||||
|
except IOError, e:
|
||||||
|
self.module.fail_json(msg="Failed to open %s: %s" % (self.sysctl_file, str(e)))
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
self.file_lines.append(line)
|
self.file_lines.append(line)
|
||||||
|
|
Loading…
Reference in a new issue