|
|
@ -36,6 +36,8 @@ from ansible import errors
|
|
|
|
|
|
|
|
|
|
|
|
################################################
|
|
|
|
################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Connection(object):
|
|
|
|
class Connection(object):
|
|
|
|
''' Handles abstract connections to remote hosts '''
|
|
|
|
''' Handles abstract connections to remote hosts '''
|
|
|
|
|
|
|
|
|
|
|
@ -73,16 +75,40 @@ class ParamikoConnection(object):
|
|
|
|
self.port = self.runner.remote_port
|
|
|
|
self.port = self.runner.remote_port
|
|
|
|
|
|
|
|
|
|
|
|
def _get_conn(self):
|
|
|
|
def _get_conn(self):
|
|
|
|
|
|
|
|
credentials = None
|
|
|
|
|
|
|
|
user = self.runner.remote_user
|
|
|
|
|
|
|
|
keypair = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Read file ~/.ssh/config, get data hostname, keyfile, port, etc
|
|
|
|
|
|
|
|
# This overrides the ansible defined username,hostname and port
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
ssh_config = paramiko.SSHConfig()
|
|
|
|
|
|
|
|
config_file = ('~/.ssh/config')
|
|
|
|
|
|
|
|
ssh_config.parse(open(os.path.expanduser(config_file)))
|
|
|
|
|
|
|
|
credentials = ssh_config.lookup(self.host)
|
|
|
|
|
|
|
|
if 'hostname' in credentials:
|
|
|
|
|
|
|
|
self.host = credentials['hostname']
|
|
|
|
|
|
|
|
if 'port' in credentials:
|
|
|
|
|
|
|
|
self.port = credentials['port']
|
|
|
|
|
|
|
|
except IOError,e:
|
|
|
|
|
|
|
|
raise errors.AnsibleConnectionFailed(str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'user' in credentials:
|
|
|
|
|
|
|
|
user = credentials['user']
|
|
|
|
|
|
|
|
if 'identityfile' in credentials:
|
|
|
|
|
|
|
|
keypair = credentials['identityfile']
|
|
|
|
|
|
|
|
|
|
|
|
ssh = paramiko.SSHClient()
|
|
|
|
ssh = paramiko.SSHClient()
|
|
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ssh.connect(
|
|
|
|
ssh.connect(
|
|
|
|
self.host,
|
|
|
|
self.host,
|
|
|
|
username=self.runner.remote_user,
|
|
|
|
username=user,
|
|
|
|
allow_agent=True,
|
|
|
|
allow_agent=True,
|
|
|
|
look_for_keys=True,
|
|
|
|
look_for_keys=True,
|
|
|
|
password=self.runner.remote_pass,
|
|
|
|
password=self.runner.remote_pass,
|
|
|
|
|
|
|
|
key_filename=keypair,
|
|
|
|
timeout=self.runner.timeout,
|
|
|
|
timeout=self.runner.timeout,
|
|
|
|
port=self.port
|
|
|
|
port=self.port
|
|
|
|
)
|
|
|
|
)
|
|
|
|