mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Report invalid connection types for network modules (#34755)
* Emit error on wrong connection type
This commit is contained in:
parent
74ac1c2e4a
commit
bd989b3088
7 changed files with 21 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue