So while troubleshooting recently, some changes to my python environment occurred. I'm under the impression I have everything back to rights, but that may not always be the case. My fab commands all seem to be failing, including with very simple tests. It seems as though it's an issue with key handling / userpass fallback with paramiko.
For instance, with this relatively simple example:
#!/usr/bin/env python
from fabric.api import *
from fabric import exceptions
import paramiko
from sys import argv
import re
import os
import getpass
import logging
logging.basicConfig(level=logging.DEBUG)
failed_hosts = {}
def run_command(Command):
try:
# print_env('run_command', Command)
# print_transport()
output = run(Command, shell = False)
return output
except exceptions.NetworkError as e:
print "Error encountered for %s: %s" % (env.host_string, e)
failed_hosts[env.host_string] = e
def test_ver():
result=run_command('sh ver')
print result
I get:
ca-cmacnevi-mac:~ christian.macnevin$ fab -f fabtest.py test_ver -u admin No hosts found. Please specify (single) host string for connection: cisco_switch [cisco_switch] run: sh ver DEBUG:paramiko.transport:starting thread (client mode): 0x3d9da90L DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_1.17.2 DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-Cisco-1.25 INFO:paramiko.transport:Connected (version 2.0, client Cisco-1.25) DEBUG:paramiko.transport:kex algos:[u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa'] client encrypt:[u'aes128-cbc', u'3des-cbc', u'aes192-cbc', u'aes256-cbc'] server encrypt:[u'aes128-cbc', u'3des-cbc', u'aes192-cbc', u'aes256-cbc'] client mac:[u'hmac-sha1', u'hmac-sha1-96', u'hmac-md5', u'hmac-md5-96'] server mac:[u'hmac-sha1', u'hmac-sha1-96', u'hmac-md5', u'hmac-md5-96'] client compress:[u'none'] server compress:[u'none'] client lang:[u''] server lang:[u''] kex follows?False DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1 DEBUG:paramiko.transport:Cipher agreed: aes128-cbc DEBUG:paramiko.transport:MAC agreed: hmac-md5 DEBUG:paramiko.transport:Compression agreed: none DEBUG:paramiko.transport:kex engine KexGroup1 specified hash_algo DEBUG:paramiko.transport:Switch to new keys ... DEBUG:paramiko.transport:Trying SSH agent key d0f5d22e756685a3640d3a24ec18bb6c DEBUG:paramiko.transport:userauth is OK DEBUG:paramiko.transport:Authentication type (publickey) not permitted. DEBUG:paramiko.transport:Allowed methods: [u'password'] [cisco_switch] Passphrase for private key: DEBUG:paramiko.transport:starting thread (client mode): 0x3dc6e50L DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_1.17.2 DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-Cisco-1.25 INFO:paramiko.transport:Connected (version 2.0, client Cisco-1.25) DEBUG:paramiko.transport:kex algos:[u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa'] client encrypt:[u'aes128-cbc', u'3des-cbc', u'aes192-cbc', u'aes256-cbc'] server encrypt:[u'aes128-cbc', u'3des-cbc', u'aes192-cbc', u'aes256-cbc'] client mac:[u'hmac-sha1', u'hmac-sha1-96', u'hmac-md5', u'hmac-md5-96'] server mac:[u'hmac-sha1', u'hmac-sha1-96', u'hmac-md5', u'hmac-md5-96'] client compress:[u'none'] server compress:[u'none'] client lang:[u''] server lang:[u''] kex follows?False DEBUG:paramiko.transport:Kex agreed: diffie-hellman-group1-sha1 DEBUG:paramiko.transport:Cipher agreed: aes128-cbc DEBUG:paramiko.transport:MAC agreed: hmac-md5 DEBUG:paramiko.transport:Compression agreed: none DEBUG:paramiko.transport:kex engine KexGroup1 specified hash_algo DEBUG:paramiko.transport:Switch to new keys ... DEBUG:paramiko.transport:Trying SSH agent key d0f5d22e756685a3640d3a24ec18bb6c DEBUG:paramiko.transport:userauth is OK DEBUG:paramiko.transport:Authentication type (publickey) not permitted. DEBUG:paramiko.transport:Allowed methods: [u'password'] DEBUG:paramiko.transport:Trying discovered key d014d32e356785aa628d3aa44cd6b265 in /Users/christian.macnevin/.ssh/id_rsa INFO:paramiko.transport:Disconnect (code 2): Protocol error: expected packet type 50, got 5 Error encountered for cisco_switch: No existing session DEBUG:paramiko.transport:EOF in transport thread None
Done.
I've seen some advice suggesting setting paramiko's 'look_for_keys' to False, but either got that wrong or it didn't help. And this all seemed to work just fine a few days ago, so I suspect there's something else at play.
Relevant:
fab --version Fabric 1.12.0 Paramiko 1.17.2
python --version Python 2.7.12
fab --host=<name of host> test_ver. Also, make sure to decorate tasks with the@taskdecorator.