From 2ec31c2c7981ad18d3e42a3a37e23ab1810cd31b Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 19 Jan 2016 08:31:10 -0500 Subject: [PATCH] fixed exception handling to be 2.4 compatible previous 'fix' broke on 2.4 --- lib/ansible/module_utils/facts.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 796ebc92bdd..197de17ce18 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2974,14 +2974,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 - finally: - datafile.close() + try: + datafile = open(path) + data = datafile.read() + if strip: + data = data.strip() + if len(data) == 0: + data = default + finally: + datafile.close() + except: + # 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 return data def get_file_lines(path):