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:
parent
eb79c14e9c
commit
47b940fc63
2 changed files with 5 additions and 2 deletions
|
@ -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).
|
|
@ -19,6 +19,7 @@ DOCUMENTATION = '''
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import pty
|
import pty
|
||||||
|
import codecs
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from ansible.module_utils._text import to_bytes, to_text
|
from ansible.module_utils._text import to_bytes, to_text
|
||||||
|
@ -85,9 +86,9 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
out_path = self._normalize_path(out_path, '/')
|
out_path = self._normalize_path(out_path, '/')
|
||||||
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
|
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()
|
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
|
# TODO test it
|
||||||
def fetch_file(self, in_path, out_path):
|
def fetch_file(self, in_path, out_path):
|
||||||
|
|
Loading…
Reference in a new issue