summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Osborn <cdosborn@uw.edu>2016-07-20 03:32:23 -0700
committerToshio Kuratomi <toshio@fedoraproject.org>2016-07-21 05:30:42 -0700
commit505a1de605941b3399593798474556f5598002bc (patch)
tree0af11456cc9bf2f38f2b1b4b507fd0aa44b8d47a
parented959d72f18f8e99d3084b2249e361e62e6579b3 (diff)
downloadansible-505a1de605941b3399593798474556f5598002bc.tar.gz
Fix exceptions thrown from cryptography import (#16723)
A simple import of cryptography can throw several types of errors. For example, if `setuptools` is less than cryptography's minimum requirement of 11.3, then this import of cryptography will throw a VersionConflict here. An earlier case threw a DistributionNotFound exception. An optional dependency should not stop ansible. If the error is more than an ImportError, log a warning, so that errors can be fixed in ansible or elsewhere.
-rw-r--r--lib/ansible/parsing/vault/__init__.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py
index b2c87f0663..ad010a7164 100644
--- a/lib/ansible/parsing/vault/__init__.py
+++ b/lib/ansible/parsing/vault/__init__.py
@@ -30,6 +30,12 @@ from hashlib import sha256
from binascii import hexlify
from binascii import unhexlify
+try:
+ from __main__ import display
+except ImportError:
+ from ansible.utils.display import Display
+ display = Display()
+
# Note: Only used for loading obsolete VaultAES files. All files are written
# using the newer VaultAES256 which does not require md5
from hashlib import md5
@@ -71,10 +77,9 @@ try:
except ImportError:
pass
except Exception as e:
- if e.__module__ == 'pkg_resources' and e.__class__.__name__ == 'DistributionNotFound':
- pass
- else:
- raise
+ display.warning("Optional dependency 'cryptography' raised an exception, falling back to 'Crypto'")
+ import traceback
+ traceback.print_exc()
from ansible.compat.six import PY3
from ansible.utils.unicode import to_unicode, to_bytes