Replace file handling with context managers in files-modules and parsing vault. (#65371)

pull/76869/head
Mads Jensen 4 years ago committed by GitHub
parent 029c991b0d
commit 07bcd13e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -242,9 +242,8 @@ def main():
original = None
lines = []
else:
f = open(path, 'rb')
original = f.read()
f.close()
with open(path, 'rb') as f:
original = f.read()
lines = original.splitlines(True)
diff = {'before': '',

@ -398,9 +398,8 @@ class FileVaultSecret(VaultSecret):
# TODO: replace with use of self.loader
try:
f = open(filename, "rb")
vault_pass = f.read().strip()
f.close()
with open(filename, "rb") as f:
vault_pass = f.read().strip()
except (OSError, IOError) as e:
raise AnsibleError("Could not read vault password file %s: %s" % (filename, e))

Loading…
Cancel
Save