{"record":{"id":"a004497126d5015b","repo":"jumpserver/jumpserver","slug":"invalid-ssh-prompt-regular-expression","errorCode":null,"errorMessage":"Invalid SSH prompt regular expression","messagePattern":"Invalid SSH prompt regular expression","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"apps/libs/ansible/modules_utils/remote_client.py","lineNumber":334,"sourceCode":"        self.module = module\n        self.gateway_server = None\n        self.client = paramiko.SSHClient()\n        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())\n        self.debug_enabled = _env_flag_enabled('JMS_REMOTE_CLIENT_DEBUG')\n        self._debug_started_at = time.monotonic()\n        self._debug_sequence = 0\n        self._channel = None\n        self._extra_secrets = set()\n\n        self.buffer_size = 1024\n        self.prompt = self.module.params['prompt']\n        try:\n            self._prompt_re = re.compile(\n                self.prompt,\n                re.DOTALL | re.IGNORECASE,\n            )\n        except (re.error, TypeError) as error:\n            raise ValueError('Invalid SSH prompt regular expression') from error\n        self.timeout = int(self.module.params.get('recv_timeout') or 0)\n        self.delay_time = int(self.module.params.get('delay_time') or 0)\n        if self.timeout <= 0:\n            raise ValueError('recv_timeout must be greater than zero')\n        if self.delay_time < 0:\n            raise ValueError('delay_time cannot be negative')\n        if self.delay_time >= self.timeout:\n            raise ValueError('delay_time must be less than recv_timeout')\n        self._last_command_sent_at = None\n        self._decoder = codecs.getincrementaldecoder('utf-8')('replace')\n        self._debug(\n            'client.init',\n            login_host=self.module.params.get('login_host'),\n            login_port=self.module.params.get('login_port'),\n            login_user=self.module.params.get('login_user'),\n            become=self.module.params.get('become'),\n            become_method=self.module.params.get('become_method'),\n            become_user=self.module.params.get('become_user'),","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/jumpserver/jumpserver/blob/6ec464fabd61b95912d539455a3a5f15f5c59fe0/apps/libs/ansible/modules_utils/remote_client.py#L316-L352","documentation":"Raised in the remote SSH client's __init__ when re.compile of the configured prompt pattern fails with re.error or TypeError — i.e. the 'prompt' module parameter is not a valid Python regular expression (compiled with re.DOTALL|re.IGNORECASE). The client relies on this regex to detect device prompts, so an invalid one is fatal at construction.","triggerScenarios":"Passing a malformed prompt regex like '[unclosed', 'a{2,1}', or backslash sequences invalid in Python regex; passing None or a non-string that makes compile raise TypeError (though a missing value usually has a default).","commonSituations":"Customizing asset prompt patterns for network devices with regex syntax valid elsewhere (POSIX/PCRE edge cases) but not Python re; escaping bugs when templating prompts; overly greedy/wrongly-bracketed patterns pasted from device docs.","solutions":["Test the prompt with Python: `import re; re.compile(p, re.DOTALL|re.IGNORECASE)`","Fix the pattern: close brackets, use valid Python regex syntax, escape special chars meant literally","Prefer simpler anchored patterns like r'[>#]\\s*$' for common network prompts"],"exampleFix":"# before\nprompt = r'[root@.*]#'  # unbalanced/invalid character class nesting\n\n# after\nprompt = r'[#$>]\\s*$'","handlingStrategy":"validation","validationCode":"import re\ntry:\n    re.compile(prompt, re.DOTALL | re.IGNORECASE)\nexcept (re.error, TypeError):\n    raise ValueError(f'Invalid prompt regex: {prompt!r}')","typeGuard":"def is_valid_prompt_regex(p) -> bool:\n    try:\n        re.compile(p, re.DOTALL | re.IGNORECASE)\n        return True\n    except (re.error, TypeError):\n        return False","tryCatchPattern":"try:\n    client = RemoteClient(module)\nexcept ValueError as e:\n    if 'prompt regular expression' in str(e):\n        module.fail_json(msg=f'Fix the asset prompt pattern: {e}')","preventionTips":["Test prompt patterns with Python re before saving to asset config","Prefer simple anchored patterns for network prompts","Escape literal characters like . $ * when matching them"],"tags":["ssh","regex","prompt","validation","network-device"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"6ec464fabd61b95912d539455a3a5f15f5c59fe0","analyzedAt":"2026-08-28T11:33:00.925Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}