diff --git a/ansible_collections/juniper/device/plugins/connection/pyez.py b/ansible_collections/juniper/device/plugins/connection/pyez.py index bd8cd0d7..d4923a83 100644 --- a/ansible_collections/juniper/device/plugins/connection/pyez.py +++ b/ansible_collections/juniper/device/plugins/connection/pyez.py @@ -503,11 +503,16 @@ def get_rpc_resp(self, rpc, ignore_warning, format): rpc_val = rpc_val.encode("utf-8") parser = etree.XMLParser(ns_clean=True, recover=True, encoding="utf-8") rpc_etree = etree.fromstring(rpc_val, parser=parser) - resp = self.dev.rpc( - rpc_etree, - normalize=bool(format == "xml"), - ignore_warning=ignore_warning, - ) + try: + resp = self.dev.rpc( + rpc_etree, + normalize=bool(format == "xml"), + ignore_warning=ignore_warning, + ) + except pyez_exception.RpcTimeoutError as ex: + raise AnsibleError("RpcTimeoutError: %s" % str(ex)) + except (pyez_exception.RpcError, pyez_exception.ConnectError) as ex: + raise AnsibleError("RpcError: %s" % str(ex)) if format == "json": return resp return etree.tostring(resp) diff --git a/ansible_collections/juniper/device/plugins/modules/rpc.py b/ansible_collections/juniper/device/plugins/modules/rpc.py index ab7d6b88..352d57a0 100644 --- a/ansible_collections/juniper/device/plugins/modules/rpc.py +++ b/ansible_collections/juniper/device/plugins/modules/rpc.py @@ -564,10 +564,17 @@ def main(): format=format, ) except Exception as ex: - if "RpcError" in (str(ex)): - raise junos_module.pyez_exception.RpcError - if "ConnectError" in (str(ex)): - raise junos_module.pyez_exception.ConnectError + junos_module.logger.debug( + 'Unable to execute RPC "%s". Error: %s', + junos_module.etree.tostring(rpc, pretty_print=True), + str(ex), + ) + result["msg"] = "Unable to execute the RPC: %s. Error: %s" % ( + junos_module.etree.tostring(rpc, pretty_print=True), + str(ex), + ) + results.append(result) + continue result["msg"] = "The RPC executed successfully." junos_module.logger.debug( 'RPC "%s" executed successfully.', @@ -576,6 +583,7 @@ def main(): except ( junos_module.pyez_exception.ConnectError, junos_module.pyez_exception.RpcError, + junos_module.pyez_exception.RpcTimeoutError, ) as ex: junos_module.logger.debug( 'Unable to execute RPC "%s". Error: %s',