mirror of
https://github.com/ansible/ansible.git
synced 2026-07-28 08:05:22 +02:00
Add winrm hostname to stdin error (#86840)
* Enhance winrm connection failure - Add winrm_hostname to the failure message for clarity - Test that we're able to reach this message with a custom action plugin * Create changelog fragment * Make action plugin less verbose * Remove more comments (they were bad)
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
minor_changes:
|
||||
- winrm connection plugin - improved error message to include target host when stdin transfer fails (https://github.com/ansible/ansible/issues/86749)
|
||||
@@ -620,7 +620,7 @@ class Connection(ConnectionBase):
|
||||
self._winrm_write_stdin(command_id, stdin_iterator)
|
||||
|
||||
except Exception as ex:
|
||||
display.error_as_warning("ERROR DURING WINRM SEND INPUT. Attempting to recover.", ex)
|
||||
display.error_as_warning(f"ERROR DURING WINRM SEND INPUT TO {self._winrm_host}. Attempting to recover.", ex)
|
||||
stdin_push_failed = True
|
||||
|
||||
# Even on a failure above we try at least once to get the output
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
from __future__ import annotations
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
"""
|
||||
Custom action plugin to trip a failure using the winrm connection plugin.
|
||||
This patches the connection's _winrm_write_stdin to fail deterministically.
|
||||
"""
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
|
||||
connection = self._connection
|
||||
original_write_stdin = connection._winrm_write_stdin
|
||||
|
||||
def failing_write_stdin(_command_id, _stdin_iterator):
|
||||
raise Exception("INJECTED TEST FAILURE: stdin write failed")
|
||||
|
||||
try:
|
||||
connection._winrm_write_stdin = failing_write_stdin
|
||||
|
||||
# Execute a module that will use stdin (pipelining is on by default)
|
||||
module_result = self._execute_module(
|
||||
module_name='ansible.windows.win_ping',
|
||||
module_args={},
|
||||
task_vars=task_vars,
|
||||
)
|
||||
|
||||
result.update(module_result)
|
||||
finally:
|
||||
connection._winrm_write_stdin = original_write_stdin
|
||||
|
||||
return result
|
||||
@@ -81,3 +81,15 @@
|
||||
assert:
|
||||
that:
|
||||
- stderr_clixml.stderr_lines == ['Test 🎵 _x005F_ _x005Z_.']
|
||||
|
||||
- name: Test stdin write failure error message
|
||||
test_stdin_failure:
|
||||
ignore_errors: true
|
||||
register: stdin_write_fail
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- stdin_write_fail is failed
|
||||
- stdin_write_fail.warnings | default([]) | select('search', warning_substring) | list | length > 0
|
||||
vars:
|
||||
warning_substring: "ERROR DURING WINRM SEND INPUT TO "
|
||||
|
||||
Reference in New Issue
Block a user