mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Make private key customizable per host using ansible_ssh_private_key_file configurable as variable
This fixes issue #1026 for @toshywoshy together with ansible_ssh_user and ansible_ssh_port.
This commit is contained in:
committed by
Michael DeHaan
parent
98e4b1f4b8
commit
d5d26bab9b
@@ -43,7 +43,7 @@ SFTP_CONNECTION_CACHE = {}
|
||||
class Connection(object):
|
||||
''' SSH based connections with Paramiko '''
|
||||
|
||||
def __init__(self, runner, host, port, user, password):
|
||||
def __init__(self, runner, host, port, user, password, private_key_file):
|
||||
|
||||
self.ssh = None
|
||||
self.sftp = None
|
||||
@@ -52,6 +52,7 @@ class Connection(object):
|
||||
self.port = port
|
||||
self.user = user
|
||||
self.password = password
|
||||
self.private_key_file = private_key_file
|
||||
|
||||
def _cache_key(self):
|
||||
return "%s__%s__" % (self.host, self.user)
|
||||
@@ -79,7 +80,9 @@ class Connection(object):
|
||||
if self.password is not None:
|
||||
allow_agent = False
|
||||
try:
|
||||
if self.runner.private_key_file:
|
||||
if self.private_key_file:
|
||||
key_filename = os.path.expanduser(self.private_key_file)
|
||||
elif self.runner.private_key_file:
|
||||
key_filename = os.path.expanduser(self.runner.private_key_file)
|
||||
else:
|
||||
key_filename = None
|
||||
|
||||
@@ -32,12 +32,13 @@ from ansible import utils
|
||||
class Connection(object):
|
||||
''' ssh based connections '''
|
||||
|
||||
def __init__(self, runner, host, port, user, password):
|
||||
def __init__(self, runner, host, port, user, password, private_key_file):
|
||||
self.runner = runner
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.user = user
|
||||
self.password = password
|
||||
self.private_key_file = private_key_file
|
||||
|
||||
def connect(self):
|
||||
''' connect to the remote host '''
|
||||
@@ -55,7 +56,9 @@ class Connection(object):
|
||||
self.common_args += ["-o", "StrictHostKeyChecking=no"]
|
||||
if self.port is not None:
|
||||
self.common_args += ["-o", "Port=%d" % (self.port)]
|
||||
if self.runner.private_key_file is not None:
|
||||
if self.private_key_file is not None:
|
||||
self.common_args += ["-o", "IdentityFile="+os.path.expanduser(self.private_key_file)]
|
||||
elif self.runner.private_key_file is not None:
|
||||
self.common_args += ["-o", "IdentityFile="+os.path.expanduser(self.runner.private_key_file)]
|
||||
if self.password:
|
||||
self.common_args += ["-o", "GSSAPIAuthentication=no",
|
||||
|
||||
Reference in New Issue
Block a user