fixes nxos nxapi implementation (#21615)

* correctly maps play_context to nxapi values
* fixes bug in nxos_nxapi module detecting nxapi feature
* updates nxos shared lib provider values
* fixes missing ssh_keyfile in nxos shared lib
This commit is contained in:
Peter Sprygada 2017-02-18 11:20:26 -05:00 committed by GitHub
parent eb6956e1dd
commit 920f9f4815
3 changed files with 19 additions and 15 deletions

View file

@ -41,12 +41,16 @@ _DEVICE_CONNECTION = None
nxos_argument_spec = { nxos_argument_spec = {
'host': dict(), 'host': dict(),
'port': dict(type='int'), 'port': dict(type='int'),
'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])), 'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True), 'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True),
'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE'])),
'use_ssl': dict(type='bool'), 'use_ssl': dict(type='bool'),
'validate_certs': dict(type='bool'), 'validate_certs': dict(type='bool'),
'timeout': dict(type='int'), 'timeout': dict(type='int'),
'provider': dict(type='dict'),
'provider': dict(type='dict', no_log=True),
'transport': dict(choices=['cli', 'nxapi']) 'transport': dict(choices=['cli', 'nxapi'])
} }
@ -347,7 +351,7 @@ def get_config(module, flags=[]):
def run_commands(module, commands, check_rc=True): def run_commands(module, commands, check_rc=True):
conn = get_connection(module) conn = get_connection(module)
return conn.run_commands(to_command(module, commands)) return conn.run_commands(to_command(module, commands), check_rc)
def load_config(module, config): def load_config(module, config):
conn = get_connection(module) conn = get_connection(module)

View file

@ -209,7 +209,7 @@ def parse_sandbox(data):
def map_config_to_obj(module): def map_config_to_obj(module):
out = run_commands(module, ['show nxapi'], check_rc=False) out = run_commands(module, ['show nxapi'], check_rc=False)
if not out[0]: if out[0] == '':
return {'state': 'absent'} return {'state': 'absent'}
out = str(out[0]).strip() out = str(out[0]).strip()

View file

@ -57,6 +57,8 @@ class ActionModule(_ActionModule):
pc.port = provider['port'] or self._play_context.port or 22 pc.port = provider['port'] or self._play_context.port or 22
pc.remote_user = provider['username'] or self._play_context.connection_user pc.remote_user = provider['username'] or self._play_context.connection_user
pc.password = provider['password'] or self._play_context.password pc.password = provider['password'] or self._play_context.password
pc.private_key_file = provider['ssh_keyfile'] or self._play_context.private_key_file
pc.timeout = provider['timeout'] or self._play_context.timeout
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin) connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
@ -71,18 +73,16 @@ class ActionModule(_ActionModule):
task_vars['ansible_socket'] = socket_path task_vars['ansible_socket'] = socket_path
else: else:
if provider['host'] is None: provider_arg = {
self._task.args['host'] = self._play_context.remote_addr 'host': self._play_context.remote_addr,
if provider['username'] is None: 'port': provider.get('port'),
self._task.args['username'] = self._play_context.connection_user 'username': provider.get('username') or self._play_context.connection_user,
if provider['password'] is None: 'password': provider.get('password') or self._play_context.password,
self._task.args['password'] = self._play_context.password 'timeout': provider.get('timeout') or self._play_context.timeout,
if provider['timeout'] is None: 'use_ssl': task_vars.get('nxapi_use_ssl') or False,
self._task.args['timeout'] = self._play_context.timeout 'validate_certs': task_vars.get('nxapi_validate_certs') or True
if task_vars.get('nxapi_use_ssl'): }
self._task.args['use_ssl'] = task_vars['nxapi_use_ssl'] self._task.args['provider'] = provider_arg
if task_vars.get('nxapi_validate_certs'):
self._task.args['validate_certs'] = task_vars['nxapi_validate_certs']
result = super(ActionModule, self).run(tmp, task_vars) result = super(ActionModule, self).run(tmp, task_vars)