Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for connection args in ntc_config_command #264

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# CHANGELOG


## [0.9.4]

### Added
- [#236] Add support for **connection_args in ntc_config_command


## [0.9.3]

### Fixed
- [#262] Account for Ansible Versions beyond 2.9


## [0.9.2]

### Fixed
- [#256] Made setup.py work with python2.7 again

40 changes: 24 additions & 16 deletions library/ntc_config_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
required: false
default: ssh
choices: ['ssh', 'telnet']
connection_args:
description:
- Transport parameters specific to netmiko, trigger, etc.
required: false
default: {}
platform:
description:
- Platform FROM the index file
Expand Down Expand Up @@ -178,6 +183,7 @@ def main():
secret=dict(required=False, type='str', no_log=True),
use_keys=dict(required=False, default=False, type='bool'),
key_file=dict(required=False, default=None),
connection_args=dict(required=False, type='dict', default={}),
)
base_argument_spec = dict(
commands=dict(required=False, type='list'),
Expand Down Expand Up @@ -213,9 +219,9 @@ def main():
secret = module.params['secret']
use_keys = module.params['use_keys']
key_file = module.params['key_file']
connection_args = module.params['connection_args']


argument_check = { 'host': host, 'username': username, 'platform': platform, 'password': password }
argument_check = {'host': host, 'username': username, 'platform': platform, 'password': password}
for key, val in argument_check.items():
if val is None:
module.fail_json(msg=str(key) + " is required")
Expand All @@ -224,8 +230,7 @@ def main():
host = socket.gethostbyname(module.params['host'])

if connection == 'telnet' and platform != 'cisco_ios':
module.fail_json(msg='only cisco_ios supports '
'telnet connection')
module.fail_json(msg='only cisco_ios supports telnet connection')

if platform == 'cisco_ios' and connection == 'telnet':
device_type = 'cisco_ios_telnet'
Expand All @@ -239,16 +244,20 @@ def main():
port = 22

if connection in ['ssh', 'telnet']:
device = ConnectHandler(device_type=device_type,
ip=socket.gethostbyname(host),
port=port,
username=username,
password=password,
secret=secret,
use_keys=use_keys,
key_file=key_file
)

device_args = dict(
device_type=device_type,
ip=socket.gethostbyname(host),
port=port,
username=username,
password=password,
secret=secret,
use_keys=use_keys,
key_file=key_file,
)
if connection_args:
device_args.update(connection_args)

device = ConnectHandler(**device_args)
if secret:
device.enable()

Expand All @@ -264,8 +273,7 @@ def main():
module.fail_json(msg="Unable to locate: {}".format(commands_file))

if (error_params(platform, output)):
module.fail_json(msg="Error executing command:\
{}".format(output))
module.fail_json(msg="Error executing command: {}".format(output))

results = {}
results['response'] = output
Expand Down
2 changes: 1 addition & 1 deletion library/ntc_show_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
choices: ['ssh', 'offline', 'netmiko_ssh', 'trigger_ssh', 'netmiko_telnet', 'telnet']
connection_args:
description:
- Transport parameters specific to netmiko, trigger, etc.
- Transport parameters specific to netmiko.
required: false
default: {}
platform:
Expand Down