From 95cfceda982ac1a11d5f0eac6207b1519b75a8b2 Mon Sep 17 00:00:00 2001 From: Peter Oliver <github.com@mavit.org.uk> Date: Thu, 19 May 2016 19:39:34 +0100 Subject: [PATCH] Catch DistributionNotFound when pycrypto is absent (#15731) * Catch DistributionNotFound when pycrypto is absent On Solaris 11, module `pkg_resources` throws `DistributionNotFound` on import if `cryptography` is installed but `pycrypto` is not. This change causes that situation to be handled gracefully. I'm not using Paramiko or Vault, so I my understanding is that I don't need `pycrpto`. I could install `pycrypto` to make the error go away, but: - The latest released version of `pycrypto` doesn't build cleanly on Solaris (https://github.com/dlitz/pycrypto/issues/184). - Solaris includes an old version of GMP that triggers warnings every time Ansible runs (https://github.com/ansible/ansible/issues/6941). I notice that I can silence these warnings with `system_warnings` in `ansible.cfg`, but not installing `pycrypto` seems like a safer solution. * Ignore only `pkg_resources.DistributionNotFound`, not other exceptions. --- lib/ansible/parsing/vault/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py index c48902a20de..b2c87f0663e 100644 --- a/lib/ansible/parsing/vault/__init__.py +++ b/lib/ansible/parsing/vault/__init__.py @@ -70,6 +70,11 @@ try: HAS_PBKDF2HMAC = True except ImportError: pass +except Exception as e: + if e.__module__ == 'pkg_resources' and e.__class__.__name__ == 'DistributionNotFound': + pass + else: + raise from ansible.compat.six import PY3 from ansible.utils.unicode import to_unicode, to_bytes