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