From 41c98d208b1419dcf4d1349541cac3251cc157cf Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Mon, 14 Jan 2019 15:32:16 -0500 Subject: [PATCH] Move errors from import to connect (#50034) (#50036) * Move errors from import to connect (#50034) (cherry picked from commit bf4ad56479a652521056c8f6fbff24f31927dee8) * Add changelog fragment. --- changelogs/fragments/50034-move-import-errors.yaml | 3 +++ lib/ansible/plugins/connection/netconf.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/50034-move-import-errors.yaml diff --git a/changelogs/fragments/50034-move-import-errors.yaml b/changelogs/fragments/50034-move-import-errors.yaml new file mode 100644 index 0000000000..a0d53bc81b --- /dev/null +++ b/changelogs/fragments/50034-move-import-errors.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- Moved error in netconf connection plugin from at import to on connection. diff --git a/lib/ansible/plugins/connection/netconf.py b/lib/ansible/plugins/connection/netconf.py index 317d239828..2dcaaf4d69 100644 --- a/lib/ansible/plugins/connection/netconf.py +++ b/lib/ansible/plugins/connection/netconf.py @@ -187,8 +187,9 @@ try: from ncclient.operations import RPCError from ncclient.transport.errors import SSHUnknownHostError from ncclient.xml_ import to_ele, to_xml + HAS_NCCLIENT = True except ImportError: - raise AnsibleError("ncclient is not installed") + HAS_NCCLIENT = False try: from __main__ import display @@ -245,8 +246,13 @@ class Connection(NetworkConnectionBase): return super(Connection, self).exec_command(cmd, in_data, sudoable) def _connect(self): - super(Connection, self)._connect() + if not HAS_NCCLIENT: + raise AnsibleError( + 'ncclient is required to use the netconf connection type.\n' + 'Please run pip install ncclient' + ) + super(Connection, self)._connect() display.display('ssh connection done, starting ncclient', log_only=True) allow_agent = True