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 original = None
lines = [] lines = []
else: else:
f = open(path, 'rb') with open(path, 'rb') as f:
original = f.read() original = f.read()
f.close()
lines = original.splitlines(True) lines = original.splitlines(True)
diff = {'before': '', diff = {'before': '',

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

Loading…
Cancel
Save