From 30ccc8e1bd356f78fe2077720ddcab372cfab69c 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 --- lib/ansible/plugins/action/vyos.py | 3 +-- lib/ansible/plugins/cliconf/vyos.py | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/action/vyos.py b/lib/ansible/plugins/action/vyos.py index d6506a6301..58cd665000 100644 --- a/lib/ansible/plugins/action/vyos.py +++ b/lib/ansible/plugins/action/vyos.py @@ -81,10 +81,9 @@ class ActionModule(ActionNetworkModule): 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('exit discard') - out = conn.get_prompt() 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 73c0c7aa08..48e5874c74 100644 --- a/lib/ansible/plugins/cliconf/vyos.py +++ b/lib/ansible/plugins/cliconf/vyos.py @@ -109,6 +109,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