diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py index 36b1e0fbbba..700664c4cd0 100644 --- a/lib/ansible/galaxy/role.py +++ b/lib/ansible/galaxy/role.py @@ -130,13 +130,11 @@ class GalaxyRole(object): install_date=datetime.datetime.utcnow().strftime("%c"), ) info_path = os.path.join(self.path, self.META_INSTALL) - try: - f = open(info_path, 'w+') - self._install_info = yaml.safe_dump(info, f) - except: - return False - finally: - f.close() + with open(info_path, 'w+') as f: + try: + self._install_info = yaml.safe_dump(info, f) + except: + return False return True