From d8e57cc60af489f8112d3c0c4ea96704d1ad0aa1 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Tue, 7 Feb 2017 05:57:44 -0500 Subject: [PATCH] starts cli if root user login is used for junos terminal (#20761) fixes #20131 --- lib/ansible/plugins/terminal/junos.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/terminal/junos.py b/lib/ansible/plugins/terminal/junos.py index d2e0891656..620aaf66a5 100644 --- a/lib/ansible/plugins/terminal/junos.py +++ b/lib/ansible/plugins/terminal/junos.py @@ -26,11 +26,17 @@ from ansible.plugins.terminal import TerminalBase from ansible.errors import AnsibleConnectionFailure +try: + from __main__ import display +except ImportError: + from ansible.utils.display import Display + display = Display() + class TerminalModule(TerminalBase): terminal_prompts_re = [ re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"), - re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"), + re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|%) ?$"), ] terminal_errors_re = [ @@ -40,6 +46,10 @@ class TerminalModule(TerminalBase): def on_open_shell(self): try: + prompt = self._get_prompt() + if prompt.strip().endswith('%'): + display.vvv('starting cli', self._connection._play_context.remote_addr) + self._exec_cli_command('cli') for c in ['set cli timestamp disable', 'set cli screen-length 0']: self._exec_cli_command(c) except AnsibleConnectionFailure: