mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Prevent traceback.
https://github.com/ansible/ansible/issues/13743#issuecomment-171520585 In some circumstance, the file fails to open. When that occurs, we can't try to close it in the finally clause. Using a context manager is the cleanest way to change the code to account for that case.
This commit is contained in:
parent
965602882a
commit
b1a56051bd
1 changed files with 5 additions and 7 deletions
|
@ -130,13 +130,11 @@ class GalaxyRole(object):
|
|||
install_date=datetime.datetime.utcnow().strftime("%c"),
|
||||
)
|
||||
info_path = os.path.join(self.path, self.META_INSTALL)
|
||||
with open(info_path, 'w+') as f:
|
||||
try:
|
||||
f = open(info_path, 'w+')
|
||||
self._install_info = yaml.safe_dump(info, f)
|
||||
except:
|
||||
return False
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in a new issue