* 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>
(cherry picked from commit 8789d7968d49fca031c91a44ce963969ad05e5bc)
... | ... |
@@ -621,9 +621,16 @@ class Connection(ConnectionBase): |
621 | 621 |
if result.status_code != 0: |
622 | 622 |
raise AnsibleError(to_native(result.std_err)) |
623 | 623 |
|
624 |
- put_output = json.loads(result.std_out) |
|
625 |
- remote_sha1 = put_output.get("sha1") |
|
624 |
+ try: |
|
625 |
+ put_output = json.loads(result.std_out) |
|
626 |
+ except ValueError: |
|
627 |
+ # stdout does not contain a valid response |
|
628 |
+ stderr = to_bytes(result.std_err, encoding='utf-8') |
|
629 |
+ if stderr.startswith(b"#< CLIXML"): |
|
630 |
+ stderr = _parse_clixml(stderr) |
|
631 |
+ raise AnsibleError('winrm put_file failed; \nstdout: %s\nstderr %s' % (to_native(result.std_out), to_native(stderr))) |
|
626 | 632 |
|
633 |
+ remote_sha1 = put_output.get("sha1") |
|
627 | 634 |
if not remote_sha1: |
628 | 635 |
raise AnsibleError("Remote sha1 was not returned") |
629 | 636 |
|