mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Close some file handles explicitly in facts.py
Helps control open file descriptor count with pypy (which is used with one coreos + ansible example). Part of a fix for https://github.com/ansible/ansible/issues/10157
This commit is contained in:
parent
9db17afc85
commit
425dee1afa
1 changed files with 7 additions and 3 deletions
|
@ -2502,9 +2502,13 @@ class SunOSVirtual(Virtual):
|
|||
def get_file_content(path, default=None):
|
||||
data = default
|
||||
if os.path.exists(path) and os.access(path, os.R_OK):
|
||||
data = open(path).read().strip()
|
||||
if len(data) == 0:
|
||||
data = default
|
||||
try:
|
||||
datafile = open(path)
|
||||
data = datafile.read().strip()
|
||||
if len(data) == 0:
|
||||
data = default
|
||||
finally:
|
||||
datafile.close()
|
||||
return data
|
||||
|
||||
def ansible_facts(module):
|
||||
|
|
Loading…
Reference in a new issue