Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore AttributeError when trying to import p paramiko #51243

Merged
merged 2 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/ansible/plugins/connection/netconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@
from ncclient.transport.errors import SSHUnknownHostError
from ncclient.xml_ import to_ele, to_xml
HAS_NCCLIENT = True
except ImportError:
NCCLIENT_IMP_ERR = None
except (ImportError, AttributeError) as err: # paramiko and gssapi are incompatible and raise AttributeError not ImportError
HAS_NCCLIENT = False
NCCLIENT_IMP_ERR = err

logging.getLogger('ncclient').setLevel(logging.INFO)

Expand Down Expand Up @@ -270,8 +272,8 @@ def exec_command(self, cmd, in_data=None, sudoable=True):
def _connect(self):
if not HAS_NCCLIENT:
raise AnsibleError(
'ncclient is required to use the netconf connection type.\n'
'Please run pip install ncclient'
'ncclient is required to use the netconf connection type: %s.\n'
'Please run pip install ncclient' % to_native(NCCLIENT_IMP_ERR)
)

self.queue_message('log', 'ssh connection done, starting ncclient')
Expand Down
7 changes: 4 additions & 3 deletions lib/ansible/plugins/connection/paramiko_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@

# prevent paramiko warning noise -- see http://stackoverflow.com/questions/3920502/
HAVE_PARAMIKO = False
PARAMIKO_IMP_ERR = None
with warnings.catch_warnings():
warnings.simplefilter("ignore")
try:
import paramiko
HAVE_PARAMIKO = True
except ImportError:
pass
except (ImportError, AttributeError) as err: # paramiko and gssapi are incompatible and raise AttributeError not ImportError
PARAMIKO_IMP_ERR = err


class MyAddPolicy(object):
Expand Down Expand Up @@ -305,7 +306,7 @@ def _connect_uncached(self):
''' activates the connection object '''

if not HAVE_PARAMIKO:
raise AnsibleError("paramiko is not installed")
raise AnsibleError("paramiko is not installed: %s" % to_native(PARAMIKO_IMP_ERR))

port = self._play_context.port or 22
display.vvv("ESTABLISH PARAMIKO SSH CONNECTION FOR USER: %s on PORT %s TO %s" % (self._play_context.remote_user, port, self._play_context.remote_addr),
Expand Down