mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Close all open filehandle (#50544)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
committed by
Brian Coca
parent
94a1d86d70
commit
db8702cdb8
@@ -52,7 +52,8 @@ class ActionModule(ActionBase):
|
||||
if not os.path.isfile(fragment) or (ignore_hidden and os.path.basename(fragment).startswith('.')):
|
||||
continue
|
||||
|
||||
fragment_content = open(self._loader.get_real_file(fragment, decrypt=decrypt), 'rb').read()
|
||||
with open(self._loader.get_real_file(fragment, decrypt=decrypt), 'rb') as fragment_fh:
|
||||
fragment_content = fragment_fh.read()
|
||||
|
||||
# always put a newline between fragments if the previous fragment didn't end with a newline.
|
||||
if add_newline:
|
||||
|
||||
@@ -86,7 +86,8 @@ class Connection(ConnectionBase):
|
||||
|
||||
out_path = self._normalize_path(out_path, '/')
|
||||
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
|
||||
content = open(in_path).read()
|
||||
with open(in_path) as in_fh:
|
||||
content = in_fh.read()
|
||||
self.client.cmd(self.host, 'file.write', [out_path, content])
|
||||
|
||||
# TODO test it
|
||||
|
||||
@@ -93,7 +93,10 @@ def parse_cli(output, tmpl):
|
||||
except ImportError as exc:
|
||||
raise AnsibleError(to_native(exc))
|
||||
|
||||
spec = yaml.safe_load(open(tmpl).read())
|
||||
with open(tmpl) as tmpl_fh:
|
||||
tmpl_content = tmpl_fh.read()
|
||||
|
||||
spec = yaml.safe_load(tmpl_content)
|
||||
obj = {}
|
||||
|
||||
for name, attrs in iteritems(spec['keys']):
|
||||
@@ -330,7 +333,10 @@ def parse_xml(output, tmpl):
|
||||
except ImportError as exc:
|
||||
raise AnsibleError(to_native(exc))
|
||||
|
||||
spec = yaml.safe_load(open(tmpl).read())
|
||||
with open(tmpl) as tmpl_fh:
|
||||
tmpl_content = tmpl_fh.read()
|
||||
|
||||
spec = yaml.safe_load(tmpl_content)
|
||||
obj = {}
|
||||
|
||||
for name, attrs in iteritems(spec['keys']):
|
||||
|
||||
Reference in New Issue
Block a user