fixes eos connection checks and checks configured connection (#32828)

This change will check the configured connection first and then check
the local provider values.
This commit is contained in:
Peter Sprygada 2017-11-13 14:28:55 -05:00 committed by Nathaniel Case
parent b9bdb05459
commit db6a72ebf9

View file

@ -37,13 +37,14 @@ except ImportError:
class ActionModule(_ActionModule):
def run(self, tmp=None, task_vars=None):
provider = load_provider(eos_provider_spec, self._task.args)
transport = provider['transport'] or 'cli'
display.vvvv('connection transport is %s' % transport, self._play_context.remote_addr)
if self._play_context.connection == 'local':
provider = load_provider(eos_provider_spec, self._task.args)
transport = provider['transport'] or 'cli'
if transport == 'cli':
if self._play_context.connection == 'local':
display.vvvv('connection transport is %s' % transport, self._play_context.remote_addr)
if transport == 'cli':
pc = copy.deepcopy(self._play_context)
pc.connection = 'network_cli'
pc.network_os = 'eos'
@ -70,29 +71,29 @@ class ActionModule(_ActionModule):
task_vars['ansible_socket'] = socket_path
else:
provider['transport'] = 'eapi'
else:
provider['transport'] = 'eapi'
if provider.get('host') is None:
provider['host'] = self._play_context.remote_addr
if provider.get('host') is None:
provider['host'] = self._play_context.remote_addr
if provider.get('port') is None:
default_port = 443 if provider['use_ssl'] else 80
provider['port'] = int(self._play_context.port or default_port)
if provider.get('port') is None:
default_port = 443 if provider['use_ssl'] else 80
provider['port'] = int(self._play_context.port or default_port)
if provider.get('timeout') is None:
provider['timeout'] = C.PERSISTENT_COMMAND_TIMEOUT
if provider.get('timeout') is None:
provider['timeout'] = C.PERSISTENT_COMMAND_TIMEOUT
if provider.get('username') is None:
provider['username'] = self._play_context.connection_user
if provider.get('username') is None:
provider['username'] = self._play_context.connection_user
if provider.get('password') is None:
provider['password'] = self._play_context.password
if provider.get('password') is None:
provider['password'] = self._play_context.password
if provider.get('authorize') is None:
provider['authorize'] = False
if provider.get('authorize') is None:
provider['authorize'] = False
self._task.args['provider'] = provider
self._task.args['provider'] = provider
result = super(ActionModule, self).run(tmp, task_vars)
return result