From 30bbbdbe3365aee6fa5d17660ff7efaea1579fd6 Mon Sep 17 00:00:00 2001 From: Xu Yuandong Date: Fri, 18 Oct 2019 17:09:47 +0800 Subject: [PATCH] action/ce.py:clear configuration candidate when return to user-view. (#63513) * clear configuration candidate when return to user-view. * add a changelog fragment for the pr. * Update 63513-ce_action_wait_prompt_trigger_time_out.yaml * Update 63513-ce_action_wait_prompt_trigger_time_out.yaml (cherry picked from commit 47c31c201b694d043e156747a4a99275bd66492e) --- .../63513-ce_action_wait_prompt_trigger_time_out.yaml | 2 ++ lib/ansible/plugins/action/ce.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/63513-ce_action_wait_prompt_trigger_time_out.yaml diff --git a/changelogs/fragments/63513-ce_action_wait_prompt_trigger_time_out.yaml b/changelogs/fragments/63513-ce_action_wait_prompt_trigger_time_out.yaml new file mode 100644 index 00000000000..bd4ac9c6d0d --- /dev/null +++ b/changelogs/fragments/63513-ce_action_wait_prompt_trigger_time_out.yaml @@ -0,0 +1,2 @@ +bugfixes: + - action/ce - fix a bug, some new version os will not discard uncommitted configure with a return directly.(https://github.com/ansible/ansible/pull/63513). diff --git a/lib/ansible/plugins/action/ce.py b/lib/ansible/plugins/action/ce.py index 18a3570d975..303ea53bbfb 100644 --- a/lib/ansible/plugins/action/ce.py +++ b/lib/ansible/plugins/action/ce.py @@ -93,10 +93,14 @@ class ActionModule(ActionNetworkModule): socket_path = self._connection.socket_path conn = Connection(socket_path) out = conn.get_prompt() - while to_text(out, errors='surrogate_then_replace').strip().endswith(']'): + prompt = to_text(out, errors='surrogate_then_replace').strip() + while prompt.endswith(']'): display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr) + if prompt.startswith('[*'): + conn.exec_command('clear configuration candidate') conn.exec_command('return') out = conn.get_prompt() + prompt = to_text(out, errors='surrogate_then_replace').strip() result = super(ActionModule, self).run(task_vars=task_vars) return result