From d29db3ecf964786c38e91f30cc704078a296fcc2 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 19 Dec 2020 18:55:57 +0000 Subject: [PATCH] saltstack: fix put_file to preserve checksum (#1472) (#1514) * saltstack: fix put_file to preserve checksum Use hashutil.base64_decodefile to ensure that the file checksum is preserved, since file.write only supports text files. Signed-off-by: Zac Medico * Update changelogs/fragments/1472-saltstack-fix-put_file-to-preserve-checksum.yml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit 47b940fc63d084bf3b62e7f711d9c928e3a7b556) Co-authored-by: Zac Medico --- .../1472-saltstack-fix-put_file-to-preserve-checksum.yml | 2 ++ plugins/connection/saltstack.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/1472-saltstack-fix-put_file-to-preserve-checksum.yml diff --git a/changelogs/fragments/1472-saltstack-fix-put_file-to-preserve-checksum.yml b/changelogs/fragments/1472-saltstack-fix-put_file-to-preserve-checksum.yml new file mode 100644 index 0000000000..7db884a7f2 --- /dev/null +++ b/changelogs/fragments/1472-saltstack-fix-put_file-to-preserve-checksum.yml @@ -0,0 +1,2 @@ +bugfixes: + - saltstack connection plugin - use ``hashutil.base64_decodefile`` to ensure that the file checksum is preserved (https://github.com/ansible-collections/community.general/pull/1472). diff --git a/plugins/connection/saltstack.py b/plugins/connection/saltstack.py index 638b04e1b4..ac521e1143 100644 --- a/plugins/connection/saltstack.py +++ b/plugins/connection/saltstack.py @@ -19,6 +19,7 @@ DOCUMENTATION = ''' import re import os import pty +import codecs import subprocess from ansible.module_utils._text import to_bytes, to_text @@ -85,9 +86,9 @@ class Connection(ConnectionBase): out_path = self._normalize_path(out_path, '/') self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.host) - with open(in_path) as in_fh: + with open(in_path, 'rb') as in_fh: content = in_fh.read() - self.client.cmd(self.host, 'file.write', [out_path, content]) + self.client.cmd(self.host, 'hashutil.base64_decodefile', [codecs.encode(content, 'base64'), out_path]) # TODO test it def fetch_file(self, in_path, out_path):