Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@Fizzadar 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