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

Fix to skip /.ssh/config if don't exist rather than raise an error.

This commit is contained in:
cocoy 2012-04-23 14:32:57 +08:00
parent 645b7a2dff
commit c844a2d072

View file

@ -75,7 +75,7 @@ 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 credentials = {}
user = self.runner.remote_user user = self.runner.remote_user
keypair = None keypair = None
@ -84,15 +84,17 @@ class ParamikoConnection(object):
try: try:
ssh_config = paramiko.SSHConfig() ssh_config = paramiko.SSHConfig()
config_file = ('~/.ssh/config') config_file = ('~/.ssh/config')
ssh_config.parse(open(os.path.expanduser(config_file))) if os.path.exists(os.path.expanduser(config_file)):
credentials = ssh_config.lookup(self.host) ssh_config.parse(open(os.path.expanduser(config_file)))
if 'hostname' in credentials: credentials = ssh_config.lookup(self.host)
self.host = credentials['hostname']
if 'port' in credentials:
self.port = credentials['port']
except IOError,e: except IOError,e:
raise errors.AnsibleConnectionFailed(str(e)) raise errors.AnsibleConnectionFailed(str(e))
if 'hostname' in credentials:
self.host = credentials['hostname']
if 'port' in credentials:
self.port = credentials['port']
if 'user' in credentials: if 'user' in credentials:
user = credentials['user'] user = credentials['user']
if 'identityfile' in credentials: if 'identityfile' in credentials: