try to capture better winrm/put_file error (#70508)

* try to capture better winrm/put_file error

fixes #70361

* Update lib/ansible/plugins/connection/winrm.py

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: Matt Davis <nitzmahone@users.noreply.github.com>
pull/70026/head
Brian Coca 4 years ago committed by GitHub
parent b285f4c675
commit 8789d7968d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- winrm - preserve winrm forensic data on put_file failures

@ -616,9 +616,16 @@ class Connection(ConnectionBase):
if result.status_code != 0:
raise AnsibleError(to_native(result.std_err))
try:
put_output = json.loads(result.std_out)
remote_sha1 = put_output.get("sha1")
except ValueError:
# stdout does not contain a valid response
stderr = to_bytes(result.std_err, encoding='utf-8')
if stderr.startswith(b"#< CLIXML"):
stderr = _parse_clixml(stderr)
raise AnsibleError('winrm put_file failed; \nstdout: %s\nstderr %s' % (to_native(result.std_out), to_native(stderr)))
remote_sha1 = put_output.get("sha1")
if not remote_sha1:
raise AnsibleError("Remote sha1 was not returned")

Loading…
Cancel
Save