From aa616b436c5ba443de4685ba496464fb25a896da Mon Sep 17 00:00:00 2001 From: Nilashish Chakraborty Date: Tue, 14 May 2019 19:17:00 +0530 Subject: [PATCH] Fix VyOS cli prompt issues (#56389) Signed-off-by: NilashishC (cherry picked from commit 30ccc8e1bd356f78fe2077720ddcab372cfab69c) Add changelog for vyos prompt fix --- changelogs/fragments/55589_fix_vyos_prompt_issues.yaml | 2 ++ lib/ansible/plugins/action/vyos.py | 6 +++--- lib/ansible/plugins/cliconf/vyos.py | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/55589_fix_vyos_prompt_issues.yaml diff --git a/changelogs/fragments/55589_fix_vyos_prompt_issues.yaml b/changelogs/fragments/55589_fix_vyos_prompt_issues.yaml new file mode 100644 index 00000000000..9800352448b --- /dev/null +++ b/changelogs/fragments/55589_fix_vyos_prompt_issues.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Fix vyos cli prompt inspection (https://github.com/ansible/ansible/pull/55589) diff --git a/lib/ansible/plugins/action/vyos.py b/lib/ansible/plugins/action/vyos.py index c4d8b3bbe56..2a3b1d0d24d 100644 --- a/lib/ansible/plugins/action/vyos.py +++ b/lib/ansible/plugins/action/vyos.py @@ -83,10 +83,10 @@ class ActionModule(_ActionModule): conn = Connection(socket_path) out = conn.get_prompt() - while to_text(out, errors='surrogate_then_replace').strip().endswith(')#'): + + if to_text(out, errors='surrogate_then_replace').strip().endswith('#'): display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr) - conn.send_command('abort') - out = conn.get_prompt() + conn.send_command('exit discard') result = super(ActionModule, self).run(task_vars=task_vars) return result diff --git a/lib/ansible/plugins/cliconf/vyos.py b/lib/ansible/plugins/cliconf/vyos.py index 14ce890a434..a979564b536 100644 --- a/lib/ansible/plugins/cliconf/vyos.py +++ b/lib/ansible/plugins/cliconf/vyos.py @@ -98,6 +98,8 @@ class Cliconf(CliconfBase): self.discard_changes() else: self.send_command('exit') + if to_text(self._connection.get_prompt(), errors='surrogate_or_strict').strip().endswith('#'): + self.discard_changes() if diff_config: resp['diff'] = diff_config