You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having a problem using a console connection in Ansible after rebooting the RE. I believe I have found the solution, but need others to verify the problem and my 'fix'.
To recreate the issue from Ansible have a playbook that reboots the RE, delay for time to allow reboot to happen, then juniper_junos_facts via the console port. The facts task should fail.
I traced the problem down into the tty.py login state machine and I think there is an error in the RE.
After a reboot the console connection does not present a login after the initial '\n' is sent to the port, and so nothing is read by the login state machine, resulting in a 10 second read timeout. The state machine then tries sending a <close/> line to the console and that is the only thing read back from the console by the state machine. The <close/> appears to match the pattern and the state machine thinks it has a successful login and then attempts to start the netconf session, which fails.
During my investigation, I checked the RE at regex101.com and it did not think the cli RE was valid as it says '-' is not properly escaped. At regex101, if I take out one \ from the RE, the tag end in <close/> matches the RE. With my testing, I have changed the RE to:
'(?P[^/\\-"]>\s*$)'
Without any documentation of the pattern, it is hard to know what the writer was trying to accomplish. My thinking is that the cli prompt is viewed as the '>' char with or without spaces at the end of line. But if it is preceded by '\', '-', '"' it might be something else that is not the cli prompt. My change switches the negative match from '\', to '/'. If '\' should also be in the negative, the pattern would have to be something like:
'(?P[^\\\\/\\-"]>\s*$)'
The pattern is on line 55 of tty.py
_RE_PAT = [
'(?P<loader>oader>\s*$)',
_re_pat_login,
'(?P<passwd>assword:\s*$)',
'(?P<badpasswd>ogin incorrect)',
'(?P<netconf_closed><!-- session end at .*-->\s*)',
'(?P<shell>%|#\s*$)',
'(?P<cli>[^\\-"]>\s*$)',
'(?P<option>Enter your option:\s*$)',
'(?P<hotkey>connection: <CTRL>Z)',
'(?P<new_cli_re>[\\/\-"]>\s*$)'
]
Just noticed that markdown is messing with how backslash is being displayed. Don't copy/paste my pattern from the text, use the pattern I added to the _RE_PAT code snippet.
The text was updated successfully, but these errors were encountered:
I am having a problem using a console connection in Ansible after rebooting the RE. I believe I have found the solution, but need others to verify the problem and my 'fix'.
To recreate the issue from Ansible have a playbook that reboots the RE, delay for time to allow reboot to happen, then juniper_junos_facts via the console port. The facts task should fail.
I traced the problem down into the tty.py login state machine and I think there is an error in the RE.
After a reboot the console connection does not present a login after the initial '\n' is sent to the port, and so nothing is read by the login state machine, resulting in a 10 second read timeout. The state machine then tries sending a <close/> line to the console and that is the only thing read back from the console by the state machine. The <close/> appears to match the pattern and the state machine thinks it has a successful login and then attempts to start the netconf session, which fails.
During my investigation, I checked the RE at regex101.com and it did not think the cli RE was valid as it says '-' is not properly escaped. At regex101, if I take out one \ from the RE, the tag end in <close/> matches the RE. With my testing, I have changed the RE to:
'(?P[^/\\-"]>\s*$)'
Without any documentation of the pattern, it is hard to know what the writer was trying to accomplish. My thinking is that the cli prompt is viewed as the '>' char with or without spaces at the end of line. But if it is preceded by '\', '-', '"' it might be something else that is not the cli prompt. My change switches the negative match from '\', to '/'. If '\' should also be in the negative, the pattern would have to be something like:
'(?P[^\\\\/\\-"]>\s*$)'
The pattern is on line 55 of tty.py
Just noticed that markdown is messing with how backslash is being displayed. Don't copy/paste my pattern from the text, use the pattern I added to the _RE_PAT code snippet.
The text was updated successfully, but these errors were encountered: