# hashlib errors on FreeBSD

**URL:** <https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906>\
**Category:** Ansible Project\
**Created:** [November 27, 2014, 7:30pm UTC](https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906 "2014-11-27T19:30:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_tancsa](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@mike\_tancsa](https://forum.ansible.com/u/mike_tancsa)\
**Post date:** [November 27, 2014, 7:30pm UTC](https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906/1 "2014-11-27T19:30:40Z")

</div>

Hi,  
On a few of my FreeBSD boxes I want to start managing via Ansible, I have run into a python deprecation error / warning I am not sure how to deal with. I am using what is in the git repo, not the older version from the ports.

% ansible -m setup site0340  
ps0340snmp.station.pioneer.ca | FAILED \>\> {  
“failed”: true,  
“msg”: “/tmp/.ansible/tmp/ansible-tmp-1417115114.01-177476480407452/setup:234: DeprecationWarning: the sha module is deprecated; use the hashlib module instead\r\n from sha import sha as \_sha1\r\nTraceback (most recent call last):\r\n File "/tmp/.ansible/tmp/ansible-tmp-1417115114.01-177476480407452/setup", line 234, in \r\n from sha import sha as \_sha1\r\n File "/usr/local/lib/python2.6/sha.py", line 10, in \r\n from hashlib import sha1 as sha\r\n File "/usr/local/lib/python2.6/hashlib.py", line 136, in \r\n md5 = \_\_get\_builtin\_constructor(‘md5’)\r\n File "/usr/local/lib/python2.6/hashlib.py", line 63, in \_\_get\_builtin\_constructor\r\n import \_md5\r\nImportError: No module named \_md5\r\n”,  
“parsed”: false  
}

What is the best way to work around this ?

% ansible --version  
ansible 1.9  
configured module search path = /usr/local/share/ansible

---

<div class="post-metadata">

**Author:** ![mike\_tancsa](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@mike\_tancsa](https://forum.ansible.com/u/mike_tancsa)\
**Post date:** [November 28, 2014, 1:36am UTC](https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906/2 "2014-11-28T01:36:21Z")

</div>

Looking at the import section that fails, should it be like the md5 exception handling and handle the second failure ?

— basic.py.bak 2014-11-27 20:35:07.000000000 -0500  
+++ basic.py 2014-11-27 20:34:31.000000000 -0500  
@@ -90,8 +90,10 @@  
from hashlib import sha1 as \_sha1  
HAVE\_HASHLIB=True  
except ImportError:

- from sha import sha as \_sha1

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [November 28, 2014, 2:58am UTC](https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906/3 "2014-11-28T02:58:43Z")

</div>

This is more than just a deprecation warning unfortunately. It seems that your system doesn’t have the usual stdlib sha1 related modules. Does freebsd not include those in its standard python packages?

I’ll be back at my computer tonight and can look at the freebsd vm I have there but I don’t remember this occurring there for me. Is this a non standard python build? Or are those modules available but in some sort of separately installable package?

-Toshio

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [November 28, 2014, 4:38am UTC](https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906/4 "2014-11-28T04:38:33Z")

</div>

I just checked my freebsd install and AFAICS, the python package has  
hashlib built into it. However I don't know how standard my install  
is. I recall that I first installed freebsd from the bootonly iso.  
After install I used "pkg install python" and that got me the python  
package that I have. Is there some other method of getting python on  
freebsd that I should be looking at instead?

-Toshio

---

<div class="post-metadata">

**Author:** ![mike\_tancsa](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@mike\_tancsa](https://forum.ansible.com/u/mike_tancsa)\
**Post date:** [November 28, 2014, 11:04am UTC](https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906/5 "2014-11-28T11:04:51Z")

</div>

I only get this error on some of the embedded units. I am not sure why some are so. The version of python is 2.6 which is rather old.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 28, 2014, 2:02pm UTC](https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906/6 "2014-11-28T14:02:44Z")

</div>

On the BSDs It is common enough that python is built from ports and  
not using the binary package, in which case it might be missing  
hashlib or parts of it depending on the selections made by the  
builder.

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [November 28, 2014, 3:34pm UTC](https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906/7 "2014-11-28T15:34:14Z")

</div>

Unfortunately, no. Md5 was being used previously in many places to checksum files. However, on boxes that have to comply with the us government fips140-2 standard, md5 is not present. So we switched to using sha1 instead. Md5 is no longer needed for operation of the modules but it’s still provided when available for backwards compat. (thus the second set of exception handling that makes importing md5 optional.)

-Toshio

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [November 28, 2014, 4:37pm UTC](https://forum.ansible.com/t/hashlib-errors-on-freebsd/16906/8 "2014-11-28T16:37:13Z")

</div>

I believe Brian has the right idea. Your build of python likely does  
not have the hash modules compiled into it. Having a hash available  
in order to checksum files is needed by many basic ansible functions  
so we can't get rid of it altogether but there are some options:

\* Install python from freebsd's prebuilt collection using pkg install  
python -- On my freebsd10 box, this version does have hashing built  
in.  
\* Rebuild python on these boxes with hashing.enabled  
\* If these are truly special purpose, embedded boxes, you could use  
the ansible modules "raw" and "script". These alllow you to execute  
commands on the remote machine and pass shell scripts you've written  
yourself to the remote machine and then execute them. These modules  
sometimes work for people managing, for instance, routers, network  
appliances, routers, and other special purpose devices without python  
installed at all. This option doesn't allow you to use the full power  
of ansible but may work if you can't get a version of python that has  
hashing onto those boxes.

If using the last option with playbooks, note that you'll have to turn  
off fact gathering for boxes which do not have a hashing function.  
For instance:
