diff --git a/changelogs/fragments/update_not_supported_exception.yaml b/changelogs/fragments/update_not_supported_exception.yaml new file mode 100644 index 000000000..5e1eee822 --- /dev/null +++ b/changelogs/fragments/update_not_supported_exception.yaml @@ -0,0 +1,4 @@ +--- +bugfixes: + - Improved module execution to gracefully handle cases where plugin support is required, providing a clear error message to the user. + - Added guidance for users to open an issue for the respective platform if plugin support is needed. diff --git a/plugins/modules/cli_restore.py b/plugins/modules/cli_restore.py index 10ccc790a..c5ed62d64 100644 --- a/plugins/modules/cli_restore.py +++ b/plugins/modules/cli_restore.py @@ -75,8 +75,9 @@ RETURN = """ """ +from ansible.module_utils._text import to_text from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.connection import Connection +from ansible.module_utils.connection import Connection, ConnectionError def validate_args(module, device_operations): @@ -108,12 +109,18 @@ def main(): result = {"changed": False} connection = Connection(module._socket_path) - running = connection.restore( - filename=module.params["filename"], - path=module.params["path"], - ) + try: + running = connection.restore( + filename=module.params["filename"], + path=module.params["path"], + ) + except ConnectionError as exc: + if exc.code == -32601: # Method not found + msg = "This platform is not supported with cli_restore. Please report an issue against this platform's cliconf plugin." + module.fail_json(msg, code=exc.code) + else: + module.fail_json(msg=to_text(exc, errors="surrogate_then_replace").strip()) result["__restore__"] = running - module.exit_json(**result)