Fix action plugin issue with network connection type in common collection (#65078)

* Fix action plugin isse with network connection type in common collection

*  For network connection in common collection the value of
   ansible_connection is the FQCN of the connection type
   For example ansible_connection=network.common.network_cli

*  Add fix in supported network action plugins to extract
   the connection name from FQCN

* Fix CI issue

* Fix review comments and update community network action plugins
This commit is contained in:
Ganesh Nalawade 2019-12-13 19:22:56 +05:30 committed by GitHub
parent d72025be75
commit 2ef47148cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 100 additions and 60 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- Fixes in network action plugins to work in network connection plugin and modules in collection

View file

@ -36,7 +36,8 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'aireos_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'aireos_config' else False
if self._play_context.connection != 'local': if self._play_context.connection != 'local':
return dict( return dict(

View file

@ -36,7 +36,8 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'aruba_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'aruba_config' else False
if self._play_context.connection != 'local': if self._play_context.connection != 'local':
return dict( return dict(

View file

@ -37,7 +37,8 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'asa_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'asa_config' else False
if self._play_context.connection == 'local': if self._play_context.connection == 'local':
provider = load_provider(asa_provider_spec, self._task.args) provider = load_provider(asa_provider_spec, self._task.args)

View file

@ -43,11 +43,13 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'bigip_imish_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'bigip_imish_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
socket_path = None socket_path = None
transport = 'rest' transport = 'rest'
if self._play_context.connection == 'network_cli': if persistent_connection == 'network_cli':
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning("'provider' is unnecessary when using 'network_cli' and will be ignored") display.warning("'provider' is unnecessary when using 'network_cli' and will be ignored")
@ -83,7 +85,7 @@ class ActionModule(ActionNetworkModule):
task_vars['ansible_socket'] = socket_path task_vars['ansible_socket'] = socket_path
if (self._play_context.connection == 'local' and transport == 'cli') or self._play_context.connection == 'network_cli': if (self._play_context.connection == 'local' and transport == 'cli') or persistent_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
if socket_path is None: if socket_path is None:

View file

@ -43,8 +43,9 @@ class ActionModule(_ActionModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
socket_path = None socket_path = None
transport = 'rest' transport = 'rest'
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection == 'network_cli': if persistent_connection == 'network_cli':
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning("'provider' is unnecessary when using 'network_cli' and will be ignored") display.warning("'provider' is unnecessary when using 'network_cli' and will be ignored")
@ -78,7 +79,7 @@ class ActionModule(_ActionModule):
task_vars['ansible_socket'] = socket_path task_vars['ansible_socket'] = socket_path
if (self._play_context.connection == 'local' and transport == 'cli') or self._play_context.connection == 'network_cli': if (self._play_context.connection == 'local' and transport == 'cli') or persistent_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
if socket_path is None: if socket_path is None:

View file

@ -31,8 +31,10 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'ce_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'ce_config' else False
socket_path = None socket_path = None
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection == 'local': if self._play_context.connection == 'local':
provider = load_provider(ce_provider_spec, self._task.args) provider = load_provider(ce_provider_spec, self._task.args)
@ -55,7 +57,7 @@ class ActionModule(ActionNetworkModule):
username=pc.remote_user, username=pc.remote_user,
password=pc.password password=pc.password
) )
if self._task.action in ['ce_netconf'] or self._task.action not in CLI_SUPPORTED_MODULES: if module_name in ['ce_netconf'] or module_name not in CLI_SUPPORTED_MODULES:
pc.connection = 'netconf' pc.connection = 'netconf'
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) connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin, task_uuid=self._task._uuid)
@ -72,14 +74,14 @@ class ActionModule(ActionNetworkModule):
# make sure a transport value is set in args # make sure a transport value is set in args
self._task.args['transport'] = transport self._task.args['transport'] = transport
self._task.args['provider'] = provider self._task.args['provider'] = provider
elif self._play_context.connection in ('netconf', 'network_cli'): elif persistent_connection in ('netconf', 'network_cli'):
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection) display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection)
del self._task.args['provider'] del self._task.args['provider']
if (self._play_context.connection == 'network_cli' and self._task.action not in CLI_SUPPORTED_MODULES) or \ if (persistent_connection == 'network_cli' and module_name not in CLI_SUPPORTED_MODULES) or \
(self._play_context.connection == 'netconf' and self._task.action in CLI_SUPPORTED_MODULES): (persistent_connection == 'netconf' and module_name in CLI_SUPPORTED_MODULES):
return {'failed': True, 'msg': "Connection type '%s' is not valid for '%s' module." return {'failed': True, 'msg': "Connection type '%s' is not valid for '%s' module."
% (self._play_context.connection, self._task.action)} % (self._play_context.connection, self._task.action)}

View file

@ -25,7 +25,7 @@ from ansible.plugins.action.normal import ActionModule as _ActionModule
class ActionModule(_ActionModule): class ActionModule(_ActionModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
if self._play_context.connection != 'network_cli': if self._play_context.connection.split('.')[-1] != 'network_cli':
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}
return super(ActionModule, self).run(task_vars=task_vars) return super(ActionModule, self).run(task_vars=task_vars)

View file

@ -28,7 +28,7 @@ class ActionModule(ActionNetworkModule):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True self._config_module = True
if self._play_context.connection != 'network_cli': if self._play_context.connection.split('.')[-1] != 'network_cli':
return {'failed': True, 'msg': 'Connection type %s is not valid for cli_config module' % self._play_context.connection} return {'failed': True, 'msg': 'Connection type %s is not valid for cli_config module' % self._play_context.connection}
return super(ActionModule, self).run(task_vars=task_vars) return super(ActionModule, self).run(task_vars=task_vars)

View file

@ -34,7 +34,8 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'cnos_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'cnos_config' else False
if self._play_context.connection == 'local': if self._play_context.connection == 'local':
provider = load_provider(cnos_provider_spec, self._task.args) provider = load_provider(cnos_provider_spec, self._task.args)

View file

@ -38,9 +38,11 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'dellos10_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'dellos10_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection == 'network_cli': if persistent_connection == 'network_cli':
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using network_cli and will be ignored') display.warning('provider is unnecessary when using network_cli and will be ignored')

View file

@ -38,10 +38,12 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'dellos6_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'dellos6_config' else False
socket_path = None socket_path = None
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection == 'network_cli': if persistent_connection == 'network_cli':
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using network_cli and will be ignored') display.warning('provider is unnecessary when using network_cli and will be ignored')

View file

@ -38,10 +38,12 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'dellos9_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'dellos9_config' else False
socket_path = None socket_path = None
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection == 'network_cli': if persistent_connection == 'network_cli':
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using network_cli and will be ignored') display.warning('provider is unnecessary when using network_cli and will be ignored')

View file

@ -29,7 +29,8 @@ class ActionModule(ActionNetworkModule):
self._config_module = True self._config_module = True
if self._play_context.connection != 'network_cli': if self._play_context.connection.split('.')[-1] != 'network_cli':
return {'failed': True, 'msg': 'Connection type %s is not valid for this module. Must use network_cli.' % self._play_context.connection} return {'failed': True, 'msg': 'Connection type %s is not valid for this module. Must use fully qualified'
' name of network_cli connection type.' % self._play_context.connection}
return super(ActionModule, self).run(task_vars=task_vars) return super(ActionModule, self).run(task_vars=task_vars)

View file

@ -34,7 +34,8 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'enos_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'enos_config' else False
if self._play_context.connection == 'local': if self._play_context.connection == 'local':
provider = load_provider(enos_provider_spec, self._task.args) provider = load_provider(enos_provider_spec, self._task.args)

View file

@ -38,8 +38,9 @@ class ActionModule(ActionNetworkModule):
module_name = self._task.action.split('.')[-1] module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'eos_config' else False self._config_module = True if module_name == 'eos_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection in ('network_cli', 'httpapi'): if persistent_connection in ('network_cli', 'httpapi'):
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection) display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection)

View file

@ -32,12 +32,14 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'exos_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'exos_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection not in ('network_cli', 'httpapi'): if persistent_connection not in ('network_cli', 'httpapi'):
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}
if self._play_context.connection == 'network_cli' and self._task.action not in self.EXOS_NETWORK_CLI_MODULES: if persistent_connection == 'network_cli' and module_name not in self.EXOS_NETWORK_CLI_MODULES:
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}
return super(ActionModule, self).run(task_vars=task_vars) return super(ActionModule, self).run(task_vars=task_vars)

View file

@ -37,8 +37,9 @@ class ActionModule(ActionNetworkModule):
module_name = self._task.action.split('.')[-1] module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'ios_config' else False self._config_module = True if module_name == 'ios_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection == 'network_cli': if persistent_connection == 'network_cli':
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using network_cli and will be ignored') display.warning('provider is unnecessary when using network_cli and will be ignored')

View file

@ -38,6 +38,7 @@ class ActionModule(ActionNetworkModule):
module_name = self._task.action.split('.')[-1] module_name = self._task.action.split('.')[-1]
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]
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)
@ -71,8 +72,8 @@ 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
elif self._play_context.connection in ('netconf', 'network_cli'): elif persistent_connection in ('netconf', 'network_cli'):
if force_cli and self._play_context.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' %
(self._play_context.connection, module_name)} (self._play_context.connection, module_name)}
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})

View file

@ -35,9 +35,11 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'ironware_config' else False module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'ironware_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection == 'network_cli': if persistent_connection == 'network_cli':
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using network_cli and will be ignored') display.warning('provider is unnecessary when using network_cli and will be ignored')

View file

@ -39,6 +39,7 @@ class ActionModule(ActionNetworkModule):
module_name = self._task.action.split('.')[-1] module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'junos_config' else False self._config_module = True if module_name == 'junos_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection == 'local': if self._play_context.connection == 'local':
provider = load_provider(junos_provider_spec, self._task.args) provider = load_provider(junos_provider_spec, self._task.args)
@ -76,7 +77,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
elif self._play_context.connection in ('netconf', 'network_cli'): elif persistent_connection in ('netconf', 'network_cli'):
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
# for legacy reasons provider value is required for junos_facts(optional) and junos_package # for legacy reasons provider value is required for junos_facts(optional) and junos_package
@ -85,8 +86,8 @@ class ActionModule(ActionNetworkModule):
display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection) display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection)
del self._task.args['provider'] del self._task.args['provider']
if (self._play_context.connection == 'network_cli' and module_name not in CLI_SUPPORTED_MODULES) or \ if (persistent_connection == 'network_cli' and module_name not in CLI_SUPPORTED_MODULES) or \
(self._play_context.connection == 'netconf' and module_name in CLI_SUPPORTED_MODULES[0:2]): (persistent_connection == 'netconf' and module_name in CLI_SUPPORTED_MODULES[0:2]):
return {'failed': True, 'msg': "Connection type '%s' is not valid for '%s' module. " return {'failed': True, 'msg': "Connection type '%s' is not valid for '%s' module. "
"Please see https://docs.ansible.com/ansible/latest/network/user_guide/platform_junos.html" "Please see https://docs.ansible.com/ansible/latest/network/user_guide/platform_junos.html"
% (self._play_context.connection, module_name)} % (self._play_context.connection, module_name)}

View file

@ -37,15 +37,16 @@ class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
socket_path = None socket_path = None
play_context = copy.deepcopy(self._play_context) network_os = self._get_network_os(task_vars)
play_context.network_os = self._get_network_os(task_vars) persistent_connection = self._play_context.connection.split('.')[-1]
result = super(ActionModule, self).run(task_vars=task_vars) result = super(ActionModule, self).run(task_vars=task_vars)
if play_context.connection != 'network_cli': if persistent_connection != 'network_cli':
# It is supported only with network_cli # It is supported only with network_cli
result['failed'] = True result['failed'] = True
result['msg'] = ('please use network_cli connection type for net_get module') result['msg'] = ('connection type %s is not valid for net_get module,'
' please use fully qualified name of network_cli connection type' % self._play_context.connection)
return result return result
try: try:

View file

@ -36,15 +36,16 @@ class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
socket_path = None socket_path = None
play_context = copy.deepcopy(self._play_context) network_os = self._get_network_os(task_vars).split('.')[-1]
play_context.network_os = self._get_network_os(task_vars) persistent_connection = self._play_context.connection.split('.')[-1]
result = super(ActionModule, self).run(task_vars=task_vars) result = super(ActionModule, self).run(task_vars=task_vars)
if play_context.connection != 'network_cli': if persistent_connection != 'network_cli':
# It is supported only with network_cli # It is supported only with network_cli
result['failed'] = True result['failed'] = True
result['msg'] = ('please use network_cli connection type for net_put module') result['msg'] = ('connection type %s is not valid for net_put module,'
' please use fully qualified name of network_cli connection type' % self._play_context.connection)
return result return result
try: try:
@ -115,7 +116,7 @@ class ActionModule(ActionBase):
) )
except Exception as exc: except Exception as exc:
if to_text(exc) == "No response from server": if to_text(exc) == "No response from server":
if play_context.network_os == 'iosxr': if network_os == 'iosxr':
# IOSXR sometimes closes socket prematurely after completion # IOSXR sometimes closes socket prematurely after completion
# of file transfer # of file transfer
result['msg'] = 'Warning: iosxr scp server pre close issue. Please check dest' result['msg'] = 'Warning: iosxr scp server pre close issue. Please check dest'

View file

@ -35,11 +35,12 @@ class ActionModule(ActionNetworkModule):
module_name = self._task.action.split('.')[-1] module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'netconf_config' else False self._config_module = True if module_name == 'netconf_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection not in ['netconf', 'local'] and module_name == 'netconf_config': if persistent_connection not in ['netconf', 'local'] and module_name == 'netconf_config':
return {'failed': True, 'msg': 'Connection type %s is not valid for netconf_config module. ' return {'failed': True, 'msg': 'Connection type %s is not valid for netconf_config module. '
'Valid connection type is netconf or local (deprecated)' % self._play_context.connection} 'Valid connection type is netconf or local (deprecated)' % self._play_context.connection}
elif self._play_context.connection not in ['netconf'] and module_name != 'netconf_config': elif persistent_connection not in ['netconf'] and module_name != 'netconf_config':
return {'failed': True, 'msg': 'Connection type %s is not valid for %s module. ' return {'failed': True, 'msg': 'Connection type %s is not valid for %s module. '
'Valid connection type is netconf.' % (self._play_context.connection, module_name)} 'Valid connection type is netconf.' % (self._play_context.connection, module_name)}

View file

@ -39,9 +39,9 @@ class ActionModule(ActionNetworkModule):
module_name = self._task.action.split('.')[-1] module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'nxos_config' else False self._config_module = True if module_name == 'nxos_config' else False
socket_path = None persistent_connection = self._play_context.connection.split('.')[-1]
if (self._play_context.connection == 'httpapi' or self._task.args.get('provider', {}).get('transport') == 'nxapi') \ if (persistent_connection == 'httpapi' or self._task.args.get('provider', {}).get('transport') == 'nxapi') \
and module_name in ('nxos_file_copy', 'nxos_nxapi'): and module_name in ('nxos_file_copy', 'nxos_nxapi'):
return {'failed': True, 'msg': "Transport type 'nxapi' is not valid for '%s' module." % (module_name)} return {'failed': True, 'msg': "Transport type 'nxapi' is not valid for '%s' module." % (module_name)}
@ -71,7 +71,7 @@ class ActionModule(ActionNetworkModule):
msg += ' Current persistent_connect_timeout setting:' + str(persistent_connect_timeout) msg += ' Current persistent_connect_timeout setting:' + str(persistent_connect_timeout)
return {'failed': True, 'msg': msg} return {'failed': True, 'msg': msg}
if self._play_context.connection in ('network_cli', 'httpapi'): if persistent_connection in ('network_cli', 'httpapi'):
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection) display.warning('provider is unnecessary when using %s and will be ignored' % self._play_context.connection)

View file

@ -466,10 +466,10 @@ class ActionModule(ActionBase):
self.play_context = copy.deepcopy(self._play_context) self.play_context = copy.deepcopy(self._play_context)
self.results = super(ActionModule, self).run(task_vars=task_vars) self.results = super(ActionModule, self).run(task_vars=task_vars)
if self.play_context.connection != 'network_cli': if self.play_context.connection.split('.')[-1] != 'network_cli':
# Plugin is supported only with network_cli # Plugin is supported only with network_cli
self.results['failed'] = True self.results['failed'] = True
self.results['msg'] = ('Connection type must be <network_cli>') self.results['msg'] = 'Connection type must be fully qualified name for network_cli connection type, got %s' % self.play_context.connection
return self.results return self.results
# Get playbook values # Get playbook values

View file

@ -31,7 +31,10 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'slxos_config' else False module_name = self._task.action.split('.')[-1]
if self._play_context.connection not in ('network_cli'): self._config_module = True if module_name == 'slxos_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if persistent_connection not in ('network_cli'):
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}
return super(ActionModule, self).run(task_vars=task_vars) return super(ActionModule, self).run(task_vars=task_vars)

View file

@ -36,8 +36,11 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'sros_config' else False module_name = self._task.action.split('.')[-1]
if self._play_context.connection == 'network_cli': persistent_connection = self._play_context.connection.split('.')[-1]
self._config_module = True if module_name == 'sros_config' else False
if persistent_connection == 'network_cli':
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using network_cli and will be ignored') display.warning('provider is unnecessary when using network_cli and will be ignored')

View file

@ -27,7 +27,10 @@ class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect del tmp # tmp no longer has any effect
self._config_module = True if self._task.action == 'voss_config' else False module_name = self._task.action.split('.')[-1]
if self._play_context.connection not in ('network_cli'): self._config_module = True if module_name == 'voss_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if persistent_connection not in ('network_cli'):
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}
return super(ActionModule, self).run(task_vars=task_vars) return super(ActionModule, self).run(task_vars=task_vars)

View file

@ -37,8 +37,9 @@ class ActionModule(ActionNetworkModule):
module_name = self._task.action.split('.')[-1] module_name = self._task.action.split('.')[-1]
self._config_module = True if module_name == 'vyos_config' else False self._config_module = True if module_name == 'vyos_config' else False
persistent_connection = self._play_context.connection.split('.')[-1]
if self._play_context.connection == 'network_cli': if persistent_connection == 'network_cli':
provider = self._task.args.get('provider', {}) provider = self._task.args.get('provider', {})
if any(provider.values()): if any(provider.values()):
display.warning('provider is unnecessary when using network_cli and will be ignored') display.warning('provider is unnecessary when using network_cli and will be ignored')