# lib/ansible/module\_utils/known\_hosts.py requires hashlib

**URL:** <https://forum.ansible.com/t/lib-ansible-module-utils-known-hosts-py-requires-hashlib/15780>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [July 25, 2014, 4:15pm UTC](https://forum.ansible.com/t/lib-ansible-module-utils-known-hosts-py-requires-hashlib/15780 "2014-07-25T16:15:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [July 25, 2014, 4:15pm UTC](https://forum.ansible.com/t/lib-ansible-module-utils-known-hosts-py-requires-hashlib/15780/1 "2014-07-25T16:15:11Z")

</div>

Between Ansible 1.5.3 and 1.6.6, lib/ansible/module\_utils/known\_hosts.py added

&nbsp;&nbsp;from hashlib import sha1

which doesn't work on target hosts who only have Python 2.4.

The 'git' module uses this, and produces this stacktrace on a target RHEL  
5 system:

&nbsp;&nbsp;&nbsp;&nbsp;Traceback (most recent call last):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File "/home/ansible/.ansible/tmp/ansible-tmp-1406298245.3-265004186822038/git", line 1840, in ?  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from hashlib import sha1  
&nbsp;&nbsp;&nbsp;&nbsp;ImportError: No module named hashlib

If we modify known\_hosts.py to just the import, like so:

&nbsp;&nbsp;+$ git diff -U0  
&nbsp;&nbsp;diff --git a/lib/ansible/module\_utils/known\_hosts.py b/lib/ansible/module\_utils/known\_hosts.py  
&nbsp;&nbsp;index 62600d7..90620f7 100644  
&nbsp;&nbsp;--- a/lib/ansible/module\_utils/known\_hosts.py  
&nbsp;&nbsp;+++ b/lib/ansible/module\_utils/known\_hosts.py  
&nbsp;&nbsp;@@ -30 +30,5 @@ import hmac  
&nbsp;&nbsp;-from hashlib import sha1  
&nbsp;&nbsp;+try:  
&nbsp;&nbsp;+ from hashlib import sha1  
&nbsp;&nbsp;+except ImportError:  
&nbsp;&nbsp;+ pass

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 25, 2014, 7:28pm UTC](https://forum.ansible.com/t/lib-ansible-module-utils-known-hosts-py-requires-hashlib/15780/2 "2014-07-25T19:28:23Z")

</div>

That’s fine, feel free to send a pull request.

We don’t have a workflow that involves patches to the mailing list, but pull requests do work great for this.

Thanks!

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [July 25, 2014, 9:06pm UTC](https://forum.ansible.com/t/lib-ansible-module-utils-known-hosts-py-requires-hashlib/15780/3 "2014-07-25T21:06:49Z")

</div>

Heh, I didn't think to check this before I'd sent mail, but there's  
actually already a fix for this in devel, in  
[https://github.com/ansible/ansible/commit/60451c20ab0cb8293a1ba51b48c600819a676626](https://github.com/ansible/ansible/commit/60451c20ab0cb8293a1ba51b48c600819a676626) --  
it just hasn't made it into a release yet, I guess.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 25, 2014, 10:03pm UTC](https://forum.ansible.com/t/lib-ansible-module-utils-known-hosts-py-requires-hashlib/15780/4 "2014-07-25T22:03:36Z")

</div>

Yeah, it deserved to be but our last series of updates have been necessarily targeted.

We are possibly considering upping the 1.7 timetable and releasing in a couple of weeks (as mentioned, Windows will still be in beta, and hoping to extend module coverage more in 1.8 timeframe).
