Skip to content

Instantly share code, notes, and snippets.

@Fizzadar
Created February 3, 2016 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fizzadar/59905e8c9fdb6fb0a0d1 to your computer and use it in GitHub Desktop.
Save Fizzadar/59905e8c9fdb6fb0a0d1 to your computer and use it in GitHub Desktop.
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()
@Fizzadar
Copy link
Author

Fizzadar commented Feb 3, 2016

On OSX: after 250 hosts, connections fail with ssh-agent: failed unless the private key is added manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment