From e93bc92d97592d62a82fc53d078754dc86c4c779 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Thu, 30 Oct 2025 04:12:21 +1000 Subject: [PATCH] Fix psrp - ReadTimeout exceptions now mark host as unreachable (#85974) (#85994) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * psrp - ReadTimeout exceptions now mark host as unreachable * add try to _exec_psrp_script * fix indent E111 * update raise format switch to raise Exception from e --------- (cherry picked from commit 9fcf1f7c587f84e773b01125b2597a858b971153) Co-authored-by: Michał Gąsior --- changelogs/fragments/85966-psrp-readtimeout.yml | 2 ++ lib/ansible/plugins/connection/psrp.py | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/85966-psrp-readtimeout.yml diff --git a/changelogs/fragments/85966-psrp-readtimeout.yml b/changelogs/fragments/85966-psrp-readtimeout.yml new file mode 100644 index 00000000000..68fb53cabfb --- /dev/null +++ b/changelogs/fragments/85966-psrp-readtimeout.yml @@ -0,0 +1,2 @@ +bugfixes: + - psrp - ReadTimeout exceptions now mark host as unreachable instead of fatal (https://github.com/ansible/ansible/issues/85966) diff --git a/lib/ansible/plugins/connection/psrp.py b/lib/ansible/plugins/connection/psrp.py index cef9b4346d7..0bc5085a7e9 100644 --- a/lib/ansible/plugins/connection/psrp.py +++ b/lib/ansible/plugins/connection/psrp.py @@ -331,7 +331,7 @@ try: from pypsrp.host import PSHost, PSHostUserInterface from pypsrp.powershell import PowerShell, RunspacePool from pypsrp.wsman import WSMan - from requests.exceptions import ConnectionError, ConnectTimeout + from requests.exceptions import ConnectionError, ConnectTimeout, ReadTimeout except ImportError as err: HAS_PYPSRP = False PYPSRP_IMP_ERR = err @@ -479,11 +479,16 @@ class Connection(ConnectionBase): pwsh_in_data = in_data display.vvv(u"PSRP: EXEC %s" % script, host=self._psrp_host) - rc, stdout, stderr = self._exec_psrp_script( - script=script, - input_data=pwsh_in_data.splitlines() if pwsh_in_data else None, - arguments=script_args, - ) + try: + rc, stdout, stderr = self._exec_psrp_script( + script=script, + input_data=pwsh_in_data.splitlines() if pwsh_in_data else None, + arguments=script_args, + ) + except ReadTimeout as e: + raise AnsibleConnectionFailure( + "HTTP read timeout during PSRP script execution" + ) from e return rc, stdout, stderr def put_file(self, in_path: str, out_path: str) -> None: