summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Sprygada <privateip@users.noreply.github.com>2016-09-22 19:52:42 -0400
committerGitHub <noreply@github.com>2016-09-22 19:52:42 -0400
commit361f3999ea155a3d679763b01e87491974fbc6a9 (patch)
tree214a932643e743853f3b319283e85132ccf3c885
parent40ffd8269d6ae2e71817c14b735a84da2e7dcd02 (diff)
downloadansible-361f3999ea155a3d679763b01e87491974fbc6a9.tar.gz
fixes issue where junos shared module was ignoring ssh_keyfile (#17712)
This fixes a problem with the Netconf transport in which the ssh keyfile wasn't being used if it was defined. The ref issue is filed against 2.1.1 but have been unable to replicate the problem in that version ref: ansible/ansible-modules-core#4966
-rw-r--r--lib/ansible/module_utils/junos.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py
index 5f7d3cc66d..9cf36da4ce 100644
--- a/lib/ansible/module_utils/junos.py
+++ b/lib/ansible/module_utils/junos.py
@@ -23,6 +23,7 @@ from distutils.version import LooseVersion
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.network import register_transport, to_list
+from ansible.module_utils.network import NetworkError
from ansible.module_utils.shell import CliBase
from ansible.module_utils.six import string_types
@@ -93,14 +94,22 @@ class Netconf(object):
def connect(self, params, **kwargs):
host = params['host']
- port = params.get('port') or 830
- user = params['username']
- passwd = params['password']
+ kwargs = dict()
+ kwargs['port'] = params.get('port') or 830
+
+ kwargs['user'] = params['username']
+
+ if params['password']:
+ kwargs['passwd'] = params['password']
+
+ if params['ssh_keyfile']:
+ kwargs['ssh_private_key_file'] = params['ssh_keyfile']
+
+ kwargs['gather_facts'] = False
try:
- self.device = Device(host, user=user, passwd=passwd, port=port,
- gather_facts=False)
+ self.device = Device(host, **kwargs)
self.device.open()
except ConnectError:
exc = get_exception()