1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

the ssh shared module will try to use keys if the password is not supplied

The current ssh shared module forces only password based authentication.  This
change will allow the ssh module to use keys if a password is not provided.
This commit is contained in:
Peter Sprygada 2015-12-08 07:34:09 -05:00
parent 5d1a2eac3e
commit 27cd7668c1

View file

@ -91,12 +91,17 @@ class Ssh(object):
def __init__(self): def __init__(self):
self.client = None self.client = None
def open(self, host, port=22, username=None, password=None, timeout=10): def open(self, host, port=22, username=None, password=None,
timeout=10, key_filename=None):
ssh = paramiko.SSHClient() ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
use_keys = password is None
ssh.connect(host, port=port, username=username, password=password, ssh.connect(host, port=port, username=username, password=password,
timeout=timeout, allow_agent=False, look_for_keys=False) timeout=timeout, allow_agent=use_keys, look_for_keys=use_keys,
key_filename=key_filename)
self.client = ssh self.client = ssh
return self.on_open() return self.on_open()