Created
February 3, 2016 23:10
-
-
Save Fizzadar/59905e8c9fdb6fb0a0d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from socket import gaierror, error as socket_error | |
from paramiko import ( | |
SSHClient, MissingHostKeyPolicy, SSHException, AuthenticationException | |
) | |
from inventory import ALL | |
logger = logging.getLogger('paramiko-test') | |
logging.basicConfig(level=logging.CRITICAL) | |
logger.setLevel(logging.DEBUG) | |
connected_hosts = {} | |
count = 0 | |
for hostname, data in ALL: | |
try: | |
client = SSHClient() | |
client.set_missing_host_key_policy(MissingHostKeyPolicy()) | |
client.connect( | |
hostname, | |
username='ubuntu', port=22, timeout=5, | |
# Add explcit pkey=RSAKey object here and it works | |
) | |
count += 1 | |
logger.info(u'\t#{0}\t{1} connected'.format(count, hostname)) | |
connected_hosts[hostname] = client | |
except AuthenticationException as e: | |
logger.error(u'Auth error on: {0}, {1}'.format(hostname, e)) | |
except SSHException as e: | |
logger.error(u'SSH error on: {0}, {1}'.format(hostname, e)) | |
except gaierror: | |
logger.error(u'Could not resolve: {0}'.format(hostname)) | |
except socket_error as e: | |
logger.error(u'Could not connect: {0}:{1}, {2}'.format( | |
hostname, 22, e | |
)) | |
import ipdb | |
ipdb.set_trace() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On OSX: after 250 hosts, connections fail with
ssh-agent: failed
unless the private key is added manually.