mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-30 20:20:21 -07:00
Warn on provider
with network_cli (#33355)
* Warn on `provider` with network_cli also unify action plugins * Add to porting guide about connection warnings
This commit is contained in:
parent
717b6e7c1a
commit
7f90c9d1a7
8 changed files with 129 additions and 87 deletions
|
@ -39,6 +39,7 @@ except ImportError:
|
|||
class ActionModule(ActionBase):
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
socket_path = None
|
||||
play_context = copy.deepcopy(self._play_context)
|
||||
play_context.network_os = self._get_network_os(task_vars)
|
||||
|
||||
|
@ -51,28 +52,32 @@ class ActionModule(ActionBase):
|
|||
f3, p3, d3 = find_module(play_context.network_os, [p2])
|
||||
module = load_module('ansible.module_utils.' + play_context.network_os, f3, p3, d3)
|
||||
|
||||
self.provider = load_provider(module.get_provider_argspec(), self._task.args)
|
||||
if play_context.connection == 'local':
|
||||
|
||||
if play_context.network_os == 'junos':
|
||||
play_context.connection = 'netconf'
|
||||
play_context.port = int(self.provider['port'] or self._play_context.port or 830)
|
||||
self.provider = load_provider(module.get_provider_argspec(), self._task.args)
|
||||
if play_context.network_os == 'junos':
|
||||
play_context.connection = 'netconf'
|
||||
play_context.port = int(self.provider['port'] or self._play_context.port or 830)
|
||||
else:
|
||||
play_context.connection = 'network_cli'
|
||||
play_context.port = int(self.provider['port'] or self._play_context.port or 22)
|
||||
|
||||
play_context.remote_addr = self.provider['host'] or self._play_context.remote_addr
|
||||
play_context.remote_user = self.provider['username'] or self._play_context.connection_user
|
||||
play_context.password = self.provider['password'] or self._play_context.password
|
||||
play_context.private_key_file = self.provider['ssh_keyfile'] or self._play_context.private_key_file
|
||||
play_context.timeout = int(self.provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
|
||||
if 'authorize' in self.provider.keys():
|
||||
play_context.become = self.provider['authorize'] or False
|
||||
play_context.become_pass = self.provider['auth_pass']
|
||||
|
||||
if self._play_context.connection == 'local':
|
||||
socket_path = self._start_connection(play_context)
|
||||
task_vars['ansible_socket'] = socket_path
|
||||
else:
|
||||
play_context.connection = 'network_cli'
|
||||
play_context.port = int(self.provider['port'] or self._play_context.port or 22)
|
||||
|
||||
play_context.remote_addr = self.provider['host'] or self._play_context.remote_addr
|
||||
play_context.remote_user = self.provider['username'] or self._play_context.connection_user
|
||||
play_context.password = self.provider['password'] or self._play_context.password
|
||||
play_context.private_key_file = self.provider['ssh_keyfile'] or self._play_context.private_key_file
|
||||
play_context.timeout = int(self.provider['timeout'] or C.PERSISTENT_COMMAND_TIMEOUT)
|
||||
if 'authorize' in self.provider.keys():
|
||||
play_context.become = self.provider['authorize'] or False
|
||||
play_context.become_pass = self.provider['auth_pass']
|
||||
|
||||
socket_path = None
|
||||
if self._play_context.connection == 'local':
|
||||
socket_path = self._start_connection(play_context)
|
||||
task_vars['ansible_socket'] = socket_path
|
||||
provider = self._task.args.get('provider', {})
|
||||
if any(provider.values()):
|
||||
display.warning('provider is unnecessary when using connection=%s and will be ignored' % play_context.connection)
|
||||
|
||||
if play_context.connection == 'network_cli':
|
||||
# make sure we are in the right cli context which should be
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue