@ -23,10 +23,13 @@ import sys
import copy
import copy
from ansible import constants as C
from ansible import constants as C
from ansible . module_utils . _text import to_text
from ansible . module_utils . connection import Connection
from ansible . module_utils . network_common import load_provider
from ansible . module_utils . junos import junos_provider_spec
from ansible . module_utils . junos import junos_provider_spec
from ansible . plugins . loader import connection_loader , module_loader
from ansible . plugins . loader import connection_loader , module_loader
from ansible . plugins . action . normal import ActionModule as _ActionModule
from ansible . plugins . action . normal import ActionModule as _ActionModule
from ansible . module_utils . network_common import load_provider
try :
try :
from __main__ import display
from __main__ import display
@ -53,7 +56,6 @@ class ActionModule(_ActionModule):
if self . _task . action == ' junos_netconf ' or ( provider [ ' transport ' ] == ' cli ' and self . _task . action == ' junos_command ' ) :
if self . _task . action == ' junos_netconf ' or ( provider [ ' transport ' ] == ' cli ' and self . _task . action == ' junos_command ' ) :
pc . connection = ' network_cli '
pc . connection = ' network_cli '
pc . port = int ( provider [ ' port ' ] or self . _play_context . port or 22 )
pc . port = int ( provider [ ' port ' ] or self . _play_context . port or 22 )
else :
else :
pc . connection = ' netconf '
pc . connection = ' netconf '
pc . port = int ( provider [ ' port ' ] or self . _play_context . port or 830 )
pc . port = int ( provider [ ' port ' ] or self . _play_context . port or 830 )
@ -64,7 +66,7 @@ class ActionModule(_ActionModule):
pc . timeout = int ( provider [ ' timeout ' ] or C . PERSISTENT_COMMAND_TIMEOUT )
pc . timeout = int ( provider [ ' timeout ' ] or C . PERSISTENT_COMMAND_TIMEOUT )
display . vvv ( ' using connection plugin %s ' % pc . connection , pc . remote_addr )
display . vvv ( ' using connection plugin %s ' % pc . connection , pc . remote_addr )
socket_path = None
if self . _play_context . connection == ' local ' :
if self . _play_context . connection == ' local ' :
connection = self . _shared_loader_obj . connection_loader . get ( ' persistent ' , pc , sys . stdin )
connection = self . _shared_loader_obj . connection_loader . get ( ' persistent ' , pc , sys . stdin )
@ -75,16 +77,20 @@ class ActionModule(_ActionModule):
' msg ' : ' unable to open shell. Please see: ' +
' msg ' : ' unable to open shell. Please see: ' +
' https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell ' }
' https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell ' }
task_vars [ ' ansible_socket ' ] = socket_path
if pc . connection == ' network_cli ' :
if pc . connection == ' network_cli ' :
# make sure we are in the right cli context which should be
# make sure we are in the right cli context which should be
# enable mode and not config module
# enable mode and not config module
rc , out , err = connection . exec_command ( ' prompt() ' )
if socket_path is None :
while str ( out ) . strip ( ) . endswith ( ' )# ' ) :
socket_path = self . _connection . socket_path
display . vvvv ( ' wrong context, sending exit to device ' , self . _play_context . remote_addr )
connection . exec_command ( ' exit ' )
rc , out , err = connection . exec_command ( ' prompt() ' )
task_vars [ ' ansible_socket ' ] = socket_path
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 )
conn . send_command ( ' exit ' )
out = conn . get_prompt ( )
result = super ( ActionModule , self ) . run ( tmp , task_vars )
result = super ( ActionModule , self ) . run ( tmp , task_vars )
return result
return result