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):