Commit 425dee1a by Toshio Kuratomi

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
parent 9db17afc
...@@ -2502,9 +2502,13 @@ class SunOSVirtual(Virtual): ...@@ -2502,9 +2502,13 @@ class SunOSVirtual(Virtual):
def get_file_content(path, default=None): def get_file_content(path, default=None):
data = default data = default
if os.path.exists(path) and os.access(path, os.R_OK): if os.path.exists(path) and os.access(path, os.R_OK):
data = open(path).read().strip() try:
if len(data) == 0: datafile = open(path)
data = default data = datafile.read().strip()
if len(data) == 0:
data = default
finally:
datafile.close()
return data return data
def ansible_facts(module): def ansible_facts(module):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment