# Unable to import MySQLdb in ansible module

**URL:** <https://forum.ansible.com/t/unable-to-import-mysqldb-in-ansible-module/14724>\
**Category:** Ansible Project\
**Created:** [March 7, 2014, 2:24pm UTC](https://forum.ansible.com/t/unable-to-import-mysqldb-in-ansible-module/14724 "2014-03-07T14:24:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roopendra\_Vishwakarm](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@Roopendra\_Vishwakarm](https://forum.ansible.com/u/Roopendra_Vishwakarm)\
**Post date:** [March 7, 2014, 2:24pm UTC](https://forum.ansible.com/t/unable-to-import-mysqldb-in-ansible-module/14724/1 "2014-03-07T14:24:25Z")

</div>

I am trying to write custom module in ansible. while using `import MySQLdb` it is giving me error

failed: [127.0.0.1] =\> {“failed”: true, “parsed”: false}  
invalid output was: Traceback (most recent call last):  
File “/root/.ansible/tmp/ansible-1394199347.29-33439012674717/inventory”, line 11, in   
import MySQLdb  
ImportError: No module named MySQLdb

Using  
**Python Version :** 2.6.6  
**MySQL-python Version :** 1.2.3

**Python Code:-**

#!/usr/bin/python

import datetime  
import sys  
import json  
import os  
import shlex  
import MySQLdb

db = MySQLdb.connect(“localhost”,“user”,“pwd”,“db\_name” )  
cursor = db.cursor()  
cursor.execute(“SELECT \* FROM hosts”)  
data = cursor.fetchone()  
print data  
db.close()

Same code working in python command line (\<\<\<) but not working in ansible module.  
Is there any configuration setting need to do for ansible??
