mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
Add prompt check in action plugin for network platform (#32787)
* Add prompt check in action plugin for network platform In case of ignore_errors for a wrong configuration the prompt is left in configuration mode and moved to next task, if the next taks requires prompt to be in operational state it results in failure. Hence add a check to ensure right prompt at start of each task run. * Add prompt check in action plugin for network platform * In case of ignore_errors for a wrong configuration the prompt is left in configuration mode and moved to next task, if the next taks requires prompt to be in operational state it results in failure. * Hence add a check to ensure right prompt at start of each task run. * Fix CI issue * Fix CI issues Fix review comment Change iosxr exit command to abort as per review comment
This commit is contained in:
parent
414eaefcb5
commit
8472a53bea
14 changed files with 149 additions and 49 deletions
|
@ -23,6 +23,8 @@ import sys
|
|||
import copy
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.connection import Connection
|
||||
from ansible.plugins.action.normal import ActionModule as _ActionModule
|
||||
from ansible.module_utils.ce import ce_provider_spec
|
||||
from ansible.module_utils.network_common import load_provider
|
||||
|
@ -78,11 +80,12 @@ class ActionModule(_ActionModule):
|
|||
|
||||
# make sure we are in the right cli context which should be
|
||||
# enable mode and not config module
|
||||
rc, out, err = connection.exec_command('prompt()')
|
||||
while str(out).strip().endswith(']'):
|
||||
conn = Connection(socket_path)
|
||||
out = conn.get_prompt()
|
||||
while to_text(out, errors='surrogate_then_replace').strip().endswith(']'):
|
||||
display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr)
|
||||
connection.exec_command('return')
|
||||
rc, out, err = connection.exec_command('prompt()')
|
||||
conn.send_command('exit')
|
||||
out = conn.get_prompt()
|
||||
|
||||
task_vars['ansible_socket'] = socket_path
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue