|
|
|
@ -111,6 +111,7 @@ import tempfile
|
|
|
|
|
from ansible.module_utils.basic import get_platform, AnsibleModule
|
|
|
|
|
from ansible.module_utils.six import string_types
|
|
|
|
|
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE
|
|
|
|
|
from ansible.module_utils._text import to_native
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SysctlModule(object):
|
|
|
|
@ -297,18 +298,17 @@ class SysctlModule(object):
|
|
|
|
|
lines = []
|
|
|
|
|
if os.path.isfile(self.sysctl_file):
|
|
|
|
|
try:
|
|
|
|
|
f = open(self.sysctl_file, "r")
|
|
|
|
|
lines = f.readlines()
|
|
|
|
|
f.close()
|
|
|
|
|
with open(self.sysctl_file, "r") as read_file:
|
|
|
|
|
lines = read_file.readlines()
|
|
|
|
|
except IOError as e:
|
|
|
|
|
self.module.fail_json(msg="Failed to open %s: %s" % (self.sysctl_file, str(e)))
|
|
|
|
|
self.module.fail_json(msg="Failed to open %s: %s" % (self.sysctl_file, to_native(e)))
|
|
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
|
line = line.strip()
|
|
|
|
|
self.file_lines.append(line)
|
|
|
|
|
|
|
|
|
|
# don't split empty lines or comments
|
|
|
|
|
if not line or line.startswith(("#", ";")):
|
|
|
|
|
# don't split empty lines or comments or line without equal sign
|
|
|
|
|
if not line or line.startswith(("#", ";")) or "=" not in line:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
k, v = line.split('=', 1)
|
|
|
|
@ -321,7 +321,7 @@ class SysctlModule(object):
|
|
|
|
|
checked = []
|
|
|
|
|
self.fixed_lines = []
|
|
|
|
|
for line in self.file_lines:
|
|
|
|
|
if not line.strip() or line.strip().startswith(("#", ";")):
|
|
|
|
|
if not line.strip() or line.strip().startswith(("#", ";")) or "=" not in line:
|
|
|
|
|
self.fixed_lines.append(line)
|
|
|
|
|
continue
|
|
|
|
|
tmpline = line.strip()
|
|
|
|
@ -351,7 +351,7 @@ class SysctlModule(object):
|
|
|
|
|
for l in self.fixed_lines:
|
|
|
|
|
f.write(l.strip() + "\n")
|
|
|
|
|
except IOError as e:
|
|
|
|
|
self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, str(e)))
|
|
|
|
|
self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, to_native(e)))
|
|
|
|
|
f.flush()
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|