1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

saltstack: fix put_file to preserve checksum (#1472)

* 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 <zmedico@gmail.com>

* Update changelogs/fragments/1472-saltstack-fix-put_file-to-preserve-checksum.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Zac Medico 2020-12-19 09:11:41 -08:00 committed by GitHub
parent eb79c14e9c
commit 47b940fc63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -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).

View file

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