From 59e1bb3e6eee70d65b2c61fb189fa69097b50adb Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Mon, 13 Jun 2016 22:39:51 -0400 Subject: [PATCH] fixes using ssh keyfile with junos network module The junos network module will now properly use the ssh key file if its passed from the playbook to authenticate to the remote device. Prior to this commit, the ssh keyfile was ignored. --- lib/ansible/module_utils/junos.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/junos.py b/lib/ansible/module_utils/junos.py index e08ad4f0b81..d32cb2dc540 100644 --- a/lib/ansible/module_utils/junos.py +++ b/lib/ansible/module_utils/junos.py @@ -93,9 +93,12 @@ class Cli(object): password = self.module.params['password'] key_filename = self.module.params['ssh_keyfile'] + allow_agent = (key_filename is not None) or (key_filename is None and password is None) + try: self.shell = Shell() - self.shell.open(host, port=port, username=username, password=password, key_filename=key_filename, allow_agent=True) + self.shell.open(host, port=port, username=username, password=password, + key_filename=key_filename, allow_agent=allow_agent) except ShellError: e = get_exception() msg = 'failed to connect to %s:%s - %s' % (host, port, str(e)) @@ -152,9 +155,10 @@ class Netconf(object): user = self.module.params['username'] passwd = self.module.params['password'] + key_filename = self.module.params['ssh_keyfile'] self.device = Device(host, user=user, passwd=passwd, port=port, - gather_facts=False).open() + gather_facts=False, ssh_private_key_file=key_filename).open() self.config = Config(self.device)