diff --git a/library/system/sysctl b/library/system/sysctl index 97e5bc5e6c1..1b29fed8f1e 100644 --- a/library/system/sysctl +++ b/library/system/sysctl @@ -235,7 +235,16 @@ class SysctlModule(object): # Get the token value from the sysctl file 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: line = line.strip() self.file_lines.append(line)