# Ansible Sanity Tests Failing Due to Unrecognized 'cryptography' Module"

**URL:** <https://forum.ansible.com/t/ansible-sanity-tests-failing-due-to-unrecognized-cryptography-module/39184>\
**Category:** Get Help\
**Created:** [December 16, 2024, 2:02pm UTC](https://forum.ansible.com/t/ansible-sanity-tests-failing-due-to-unrecognized-cryptography-module/39184 "2024-12-16T14:02:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kumar](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kumar/32/5186_2.png) [@kumar](https://forum.ansible.com/u/kumar)\
**Post date:** [December 16, 2024, 2:02pm UTC](https://forum.ansible.com/t/ansible-sanity-tests-failing-due-to-unrecognized-cryptography-module/39184/1 "2024-12-16T14:02:55Z")

</div>

Hi,

We have implemented a custom lookup plugin in Ansible that includes a certificate validation feature.

To perform the certificate validation, we are using the Python cryptography module. However, during the Ansible sanity tests, we are encountering the following error, causing the tests to fail:

**Error:**  
ERROR: Found 1 import issue(s) on Python 3.12 that need to be resolved:

ERROR: plugins/lookup/test.py:170:0: traceback: ModuleNotFoundError: No module named ‘cryptography’

**Modules used in the code:**

from cryptography.x509 import load\_pem\_x509\_certificate

from cryptography.hazmat.backends import default\_backend

The cryptography module is already available in the Python environment, but it seems that the Ansible sanity tests are unable to recognize it.

Could you please assist me in resolving this issue?

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [December 16, 2024, 3:46pm UTC](https://forum.ansible.com/t/ansible-sanity-tests-failing-due-to-unrecognized-cryptography-module/39184/2 "2024-12-16T15:46:11Z")

</div>

Your code needs to be importable even when custom libraries are not available, so you should use try/except and then handle the missing library gracefully at runtime.

For example:

> <https://github.com/ansible-collections/community.windows/blob/237af1a0a5b961c335b5d194bdcea2be3d6ffb8d/plugins/lookup/laps_password.py#L194-L201>

> <https://github.com/ansible-collections/community.windows/blob/237af1a0a5b961c335b5d194bdcea2be3d6ffb8d/plugins/lookup/laps_password.py#L234-L237>

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [December 16, 2024, 5:01pm UTC](https://forum.ansible.com/t/ansible-sanity-tests-failing-due-to-unrecognized-cryptography-module/39184/3 "2024-12-16T17:01:38Z")

</div>

There’s also [import — Ansible Community Documentation](https://docs.ansible.com/ansible/devel/dev_guide/testing/sanity/import.html) which documents what to do if you encounter failures due to the `import` sanity test.

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [December 16, 2024, 6:53pm UTC](https://forum.ansible.com/t/ansible-sanity-tests-failing-due-to-unrecognized-cryptography-module/39184/4 "2024-12-16T18:53:04Z")

</div>

Ah, thanks, I knew that had to be documented somewhere but wasn’t able to track it down.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [December 16, 2024, 7:30pm UTC](https://forum.ansible.com/t/ansible-sanity-tests-failing-due-to-unrecognized-cryptography-module/39184/5 "2024-12-16T19:30:24Z")

</div>

It is in my permanent browsing history, I just have to type “im” to get it as the first suggestion 😉
