diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index c5dc1f9ac8..3cb66a83e8 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2981,17 +2981,19 @@ def get_file_content(path, default=None, strip=True): data = default if os.path.exists(path) and os.access(path, os.R_OK): try: - datafile = open(path) - data = datafile.read() - if strip: - data = data.strip() - if len(data) == 0: - data = default + try: + datafile = open(path) + data = datafile.read() + if strip: + data = data.strip() + if len(data) == 0: + data = default + finally: + datafile.close() except: - # todo: issue warning about unreadable file? + # ignore errors as some jails/containers might have readable permissions but not allow reads to proc + # done in 2 blocks for 2.4 compat pass - finally: - datafile.close() return data def get_file_lines(path):