Error regular expression

This commit is contained in:
Yousefnezhad 2025-06-11 11:18:19 +03:30
commit 37bd9a51dc

View file

@ -63,6 +63,10 @@ import re
def get_exports(module, output_format, file_path="/etc/exports"): def get_exports(module, output_format, file_path="/etc/exports"):
IP_ENTRY_PATTERN = re.compile(r'(\d+\.\d+\.\d+\.\d+)\(([^)]+)\)')
try: try:
exports_file_digest = module.digest_from_file(file_path, 'sha1') exports_file_digest = module.digest_from_file(file_path, 'sha1')
if exports_file_digest is None: if exports_file_digest is None:
@ -90,7 +94,10 @@ def get_exports(module, output_format, file_path="/etc/exports"):
folder = match.group(1) folder = match.group(1)
rest = match.group(2) rest = match.group(2)
entries = re.findall(r'(\d+\.\d+\.\d+\.\d+)\(([^)]+)\)', rest)
entries = IP_ENTRY_PATTERN.findall(rest)
for ip, options_str in entries: for ip, options_str in entries:
options = options_str.split(',') options = options_str.split(',')
@ -112,6 +119,7 @@ def get_exports(module, output_format, file_path="/etc/exports"):
} }
except Exception as e: except Exception as e:
module.fail_json(msg="Error while processing exports: {}".format(e)) module.fail_json(msg="Error while processing exports: {}".format(e))