summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorFedele Mantuano <mantuano.fedele@gmail.com>2018-01-02 17:03:44 +0100
committerMatt Martz <matt@sivel.net>2018-01-02 10:03:44 -0600
commit70fd5d4caf65bdbafd1be023562bb9d28f7d0b6f (patch)
treeada7870bd3e6b7c085dce32287915aef43447dbc /contrib
parent0eb2644c1cd1492cf421de1f1723994047024cff (diff)
downloadansible-70fd5d4caf65bdbafd1be023562bb9d28f7d0b6f.tar.gz
More stable explicit file close. (#34303)
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/inventory/openstack.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/contrib/inventory/openstack.py b/contrib/inventory/openstack.py
index b451f312a0..30007e408c 100755
--- a/contrib/inventory/openstack.py
+++ b/contrib/inventory/openstack.py
@@ -118,9 +118,11 @@ def get_host_groups(inventory, refresh=False, cloud=None):
(cache_file, cache_expiration_time) = get_cache_settings(cloud)
if is_cache_stale(cache_file, cache_expiration_time, refresh=refresh):
groups = to_json(get_host_groups_from_cloud(inventory))
- open(cache_file, 'w').write(groups)
+ with open(cache_file, 'w') as f:
+ f.write(groups)
else:
- groups = open(cache_file, 'r').read()
+ with open(cache_file, 'r') as f:
+ groups = f.read()
return groups