fact gathering, prevent "UnboundLocalError: local variable 'datafile' referenced before assignment" when open(path) fails. (#76751)

Co-authored-by: jean kahrs <j.kahrs@hosting.de>
pull/74828/merge
jkahrs 3 years ago committed by GitHub
parent e33e7233d0
commit c8dd96b076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- gather_facts - Fact gathering now continues even if it fails to read a file

@ -32,6 +32,7 @@ def get_file_content(path, default=None, strip=True):
'''
data = default
if os.path.exists(path) and os.access(path, os.R_OK):
datafile = None
try:
datafile = open(path)
try:
@ -55,7 +56,8 @@ def get_file_content(path, default=None, strip=True):
# ignore errors as some jails/containers might have readable permissions but not allow reads
pass
finally:
datafile.close()
if datafile is not None:
datafile.close()
return data

Loading…
Cancel
Save