mirror of https://github.com/ansible/ansible
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)pull/86851/head
parent
00b1f27d9c
commit
a250aafa9f
@ -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)
|
||||
@ -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
|
||||
Loading…
Reference in new issue