mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 04:11:25 -07:00
[PR #9579/0de39a6f backport][stable-10] use open() as context manager (#9596)
use open() as context manager (#9579)
* use open() as context manager
* add changelog frag
(cherry picked from commit 0de39a6f47
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
98d25a3e4d
commit
e9b58cfc09
13 changed files with 72 additions and 102 deletions
|
@ -105,9 +105,8 @@ def gather_cloud_init_data_facts(module):
|
|||
json_file = os.path.join(CLOUD_INIT_PATH, i + '.json')
|
||||
|
||||
if os.path.exists(json_file):
|
||||
f = open(json_file, 'rb')
|
||||
contents = to_text(f.read(), errors='surrogate_or_strict')
|
||||
f.close()
|
||||
with open(json_file, 'rb') as f:
|
||||
contents = to_text(f.read(), errors='surrogate_or_strict')
|
||||
|
||||
if contents:
|
||||
res['cloud_init_data_facts'][i] = module.from_json(contents)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue