diff --git a/lib/ansible/plugins/action/eos.py b/lib/ansible/plugins/action/eos.py index aa980044d97..51bff914a87 100644 --- a/lib/ansible/plugins/action/eos.py +++ b/lib/ansible/plugins/action/eos.py @@ -101,6 +101,8 @@ class ActionModule(_ActionModule): provider['authorize'] = False self._task.args['provider'] = provider + else: + return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection} if (self._play_context.connection == 'local' and transport == 'cli') or self._play_context.connection == 'network_cli': # make sure we are in the right cli context which should be diff --git a/lib/ansible/plugins/action/ios.py b/lib/ansible/plugins/action/ios.py index f8060b175e7..13dbb47ac50 100644 --- a/lib/ansible/plugins/action/ios.py +++ b/lib/ansible/plugins/action/ios.py @@ -72,6 +72,8 @@ class ActionModule(_ActionModule): 'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'} task_vars['ansible_socket'] = socket_path + else: + return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection} # make sure we are in the right cli context which should be # enable mode and not config module diff --git a/lib/ansible/plugins/action/iosxr.py b/lib/ansible/plugins/action/iosxr.py index 3fed63f5e79..8c37bad99a1 100644 --- a/lib/ansible/plugins/action/iosxr.py +++ b/lib/ansible/plugins/action/iosxr.py @@ -73,10 +73,12 @@ class ActionModule(_ActionModule): 'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'} task_vars['ansible_socket'] = socket_path - else: + elif self._play_context.connection in ('netconf', 'network_cli'): provider = self._task.args.get('provider', {}) if any(provider.values()): display.warning('provider is unnecessary when using {0} and will be ignored'.format(self._play_context.connection)) + else: + return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection} # make sure we are in the right cli context which should be # enable mode and not config module diff --git a/lib/ansible/plugins/action/junos.py b/lib/ansible/plugins/action/junos.py index 86ac4eae361..2fa40a5e67d 100644 --- a/lib/ansible/plugins/action/junos.py +++ b/lib/ansible/plugins/action/junos.py @@ -75,10 +75,12 @@ class ActionModule(_ActionModule): 'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'} task_vars['ansible_socket'] = socket_path - else: + elif self._play_context.connection in ('netconf', 'network_cli'): provider = self._task.args.get('provider', {}) if any(provider.values()): display.warning('provider is unnecessary when using connection=%s and will be ignored' % self._play_context.connection) + else: + return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection} if (self._play_context.connection == 'local' and pc.connection == 'network_cli') or self._play_context.connection == 'network_cli': # make sure we are in the right cli context which should be diff --git a/lib/ansible/plugins/action/nxos.py b/lib/ansible/plugins/action/nxos.py index 874cde018b9..cc6d757c2f0 100644 --- a/lib/ansible/plugins/action/nxos.py +++ b/lib/ansible/plugins/action/nxos.py @@ -101,6 +101,8 @@ class ActionModule(_ActionModule): provider['validate_certs'] = True self._task.args['provider'] = provider + else: + return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection} if (self._play_context.connection == 'local' and transport == 'cli') or self._play_context.connection == 'network_cli': # make sure we are in the right cli context which should be diff --git a/lib/ansible/plugins/action/sros.py b/lib/ansible/plugins/action/sros.py index a2e3ecadc36..ae044d636fb 100644 --- a/lib/ansible/plugins/action/sros.py +++ b/lib/ansible/plugins/action/sros.py @@ -38,7 +38,11 @@ class ActionModule(_ActionModule): def run(self, tmp=None, task_vars=None): - if self._play_context.connection == 'local': + if self._play_context.connection == 'network_cli': + provider = self._task.args.get('provider', {}) + if any(provider.values()): + display.warning('provider is unnecessary when using network_cli and will be ignored') + elif self._play_context.connection == 'local': provider = load_provider(sros_provider_spec, self._task.args) pc = copy.deepcopy(self._play_context) @@ -62,6 +66,8 @@ class ActionModule(_ActionModule): 'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'} task_vars['ansible_socket'] = socket_path + else: + return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection} result = super(ActionModule, self).run(tmp, task_vars) return result diff --git a/lib/ansible/plugins/action/vyos.py b/lib/ansible/plugins/action/vyos.py index 74414b8eb52..965cd75cb06 100644 --- a/lib/ansible/plugins/action/vyos.py +++ b/lib/ansible/plugins/action/vyos.py @@ -68,6 +68,8 @@ class ActionModule(_ActionModule): 'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell'} task_vars['ansible_socket'] = socket_path + else: + return {'failed': True, 'msg': 'Connection type %s is not valid for this module' % self._play_context.connection} # make sure we are in the right cli context which should be # enable mode and not config module