@ -39,27 +39,40 @@ class ActionModule(ActionNetworkModule):
self . _config_module = True if module_name == ' iosxr_config ' else False
self . _config_module = True if module_name == ' iosxr_config ' else False
force_cli = module_name in ( ' iosxr_netconf ' , ' iosxr_config ' , ' iosxr_command ' , ' iosxr_facts ' )
force_cli = module_name in ( ' iosxr_netconf ' , ' iosxr_config ' , ' iosxr_command ' , ' iosxr_facts ' )
persistent_connection = self . _play_context . connection . split ( ' . ' ) [ - 1 ]
persistent_connection = self . _play_context . connection . split ( ' . ' ) [ - 1 ]
warnings = [ ]
if self . _play_context . connection == ' local ' :
if self . _play_context . connection == ' local ' :
provider = load_provider ( iosxr_provider_spec , self . _task . args )
provider = load_provider ( iosxr_provider_spec , self . _task . args )
pc = copy . deepcopy ( self . _play_context )
pc = copy . deepcopy ( self . _play_context )
pc . network_os = ' cisco.iosxr.iosxr '
if force_cli or provider [ ' transport ' ] == ' cli ' :
if force_cli or provider [ ' transport ' ] == ' cli ' :
pc . connection = ' network_cli'
pc . connection = ' ansible.netcommon. 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 )
elif provider [ ' transport ' ] == ' netconf ' :
elif provider [ ' transport ' ] == ' netconf ' :
pc . connection = ' netconf'
pc . connection = ' ansible.netcommon. 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 )
else :
else :
return { ' failed ' : True , ' msg ' : ' Transport type %s is not valid for this module ' % provider [ ' transport ' ] }
return { ' failed ' : True , ' msg ' : ' Transport type %s is not valid for this module ' % provider [ ' transport ' ] }
pc . network_os = ' iosxr '
pc . remote_addr = provider [ ' host ' ] or self . _play_context . remote_addr
pc . remote_addr = provider [ ' host ' ] or self . _play_context . remote_addr
pc . port = int ( provider [ ' port ' ] or self . _play_context . port or 22 )
pc . port = int ( provider [ ' port ' ] or self . _play_context . port or 22 )
pc . remote_user = provider [ ' username ' ] or self . _play_context . connection_user
pc . remote_user = provider [ ' username ' ] or self . _play_context . connection_user
pc . password = provider [ ' password ' ] or self . _play_context . password
pc . password = provider [ ' password ' ] or self . _play_context . password
connection = self . _shared_loader_obj . connection_loader . get ( ' ansible.netcommon.persistent ' , pc , sys . stdin ,
task_uuid = self . _task . _uuid )
# TODO: Remove below code after ansible minimal is cut out
if connection is None :
pc . network_os = ' iosxr '
if pc . connection . split ( ' . ' ) [ - 1 ] == ' netconf ' :
pc . connection = ' netconf '
else :
pc . connection = ' network_cli '
connection = self . _shared_loader_obj . connection_loader . get ( ' persistent ' , pc , sys . stdin , task_uuid = self . _task . _uuid )
display . vvv ( ' using connection plugin %s (was local) ' % pc . connection , pc . remote_addr )
display . vvv ( ' using connection plugin %s (was local) ' % pc . connection , pc . remote_addr )
connection = self . _shared_loader_obj . connection_loader . get ( ' persistent ' , pc , sys . stdin , task_uuid = self . _task . _uuid )
command_timeout = int ( provider [ ' timeout ' ] ) if provider [ ' timeout ' ] else connection . get_option ( ' persistent_command_timeout ' )
command_timeout = int ( provider [ ' timeout ' ] ) if provider [ ' timeout ' ] else connection . get_option ( ' persistent_command_timeout ' )
connection . set_options ( direct = { ' persistent_command_timeout ' : command_timeout } )
connection . set_options ( direct = { ' persistent_command_timeout ' : command_timeout } )
@ -72,6 +85,7 @@ class ActionModule(ActionNetworkModule):
' 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
task_vars [ ' ansible_socket ' ] = socket_path
warnings . append ( [ ' connection local support for this module is deprecated and will be removed in version 2.14, use connection %s ' % pc . connection ] )
elif persistent_connection in ( ' netconf ' , ' network_cli ' ) :
elif persistent_connection in ( ' netconf ' , ' network_cli ' ) :
if force_cli and persistent_connection != ' network_cli ' :
if force_cli and persistent_connection != ' network_cli ' :
return { ' failed ' : True , ' msg ' : ' Connection type %s is not valid for module %s ' %
return { ' failed ' : True , ' msg ' : ' Connection type %s is not valid for module %s ' %
@ -84,4 +98,9 @@ class ActionModule(ActionNetworkModule):
return { ' failed ' : True , ' msg ' : ' Connection type %s is not valid for this module ' % self . _play_context . connection }
return { ' failed ' : True , ' msg ' : ' Connection type %s is not valid for this module ' % self . _play_context . connection }
result = super ( ActionModule , self ) . run ( task_vars = task_vars )
result = super ( ActionModule , self ) . run ( task_vars = task_vars )
if warnings :
if ' warnings ' in result :
result [ ' warnings ' ] . extend ( warnings )
else :
result [ ' warnings ' ] = warnings
return result
return result