diff options
author | Toshio Kuratomi <toshio@fedoraproject.org> | 2015-02-09 13:06:33 -0800 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2015-02-17 14:26:44 -0600 |
commit | 8be771606430caf392db3a6215545bec95c80457 (patch) | |
tree | 1e46902dbeb5e713a9805f16dde3ec521a6b0ecd | |
parent | 0af7e212a8cbe77325a9e41be03e46c1eae31cc8 (diff) | |
download | ansible-8be771606430caf392db3a6215545bec95c80457.tar.gz |
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
-rw-r--r-- | lib/ansible/module_utils/facts.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 5ceeb405d5..2db9d8ccff 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2381,9 +2381,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): |