# MYSQL Connectivity Issue in Ansible

**URL:** <https://forum.ansible.com/t/mysql-connectivity-issue-in-ansible/23372>\
**Category:** Ansible Project\
**Created:** [January 4, 2017, 4:48am UTC](https://forum.ansible.com/t/mysql-connectivity-issue-in-ansible/23372 "2017-01-04T04:48:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mona\_Gopal](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mona\_Gopal](https://forum.ansible.com/u/Mona_Gopal)\
**Post date:** [January 4, 2017, 4:48am UTC](https://forum.ansible.com/t/mysql-connectivity-issue-in-ansible/23372/1 "2017-01-04T04:48:57Z")

</div>

Hello,

I have the below task

mysql\_user: login\_user={{ db\_user\_root }} login\_password={{ db\_pass\_root }} name={{ db\_user }} password={{ db\_pass }} priv=_._:ALL,GRANT state=present

We’re facing issue on running this, from machine B to install on machine A. Installing from machine A to machine B is running fine.

However, by specifying login\_host parameter this works fine.

But, the same parameter is not essential while running from A to B.

What could be the scenario?? why is that login\_host parameter is required when running from B to A and not vice versa.

Thanks in advance,

Mona G

---

<div class="post-metadata">

**Author:** ![toshywoshy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/toshywoshy/32/7855_2.png) [@toshywoshy](https://forum.ansible.com/u/toshywoshy)\
**Post date:** [January 4, 2017, 9:40am UTC](https://forum.ansible.com/t/mysql-connectivity-issue-in-ansible/23372/2 "2017-01-04T09:40:08Z")

</div>

> Hello,
> 
> I have the below task
> 
> mysql\_user: login\_user={{ db\_user\_root }} login\_password={{ db\_pass\_root  
> }} name={{ db\_user }} password={{ db\_pass }} priv=\*.\*:ALL,GRANT  
> state=present
> 
> We're facing issue on running this, from machine B to install on machine  
> A. Installing from machine A to machine B is running fine.
> 
> However, by specifying login\_host parameter this works fine.
> 
> But, the same parameter is not essential while running from A to B.
> 
> What could be the scenario?? why is that login\_host parameter is  
> required when running from B to A and not vice versa.

I would be guessing, because you do not give enough information.  
I presume that your server my.cnf bind only to an IP on machine A, while machine B has a UNIX socket connection, the default MySQL python module uses a UNIX socket connection, while you can override that by using the 'login\_host' variable and then the module will use a TCP socket  
Another possibility is that your user running the Ansible task has a .my.cnf in $HOME which overrides the default host value, so you need to specify the correct one manually

However this is a wild guess, for a better answer, more information is required.

> Thanks in advance,
> 
> Mona G

Regards,  
Tosh.

---

<div class="post-metadata">

**Author:** ![Mona\_Gopal](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mona\_Gopal](https://forum.ansible.com/u/Mona_Gopal)\
**Post date:** [January 4, 2017, 9:55am UTC](https://forum.ansible.com/t/mysql-connectivity-issue-in-ansible/23372/3 "2017-01-04T09:55:57Z")

</div>

Dear Tosh,

Thanks a lot for your response 🙂  
We are checking on the parameters that you mentioned.  
Can you list out what more information is required for a better analysis of the same.

Regards,  
Mona G

---

<div class="post-metadata">

**Author:** ![toshywoshy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/toshywoshy/32/7855_2.png) [@toshywoshy](https://forum.ansible.com/u/toshywoshy)\
**Post date:** [January 4, 2017, 11:42am UTC](https://forum.ansible.com/t/mysql-connectivity-issue-in-ansible/23372/4 "2017-01-04T11:42:10Z")

</div>

> &nbsp;&nbsp;&nbsp;&nbsp;\> Hello,  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> I have the below task  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> mysql\_user: login\_user={{ db\_user\_root }} login\_password={{  
> &nbsp;&nbsp;&nbsp;&nbsp;db\_pass\_root  
> &nbsp;&nbsp;&nbsp;&nbsp;\> }} name={{ db\_user }} password={{ db\_pass }} priv=\*.\*:ALL,GRANT  
> &nbsp;&nbsp;&nbsp;&nbsp;\> state=present  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> We're facing issue on running this, from machine B to install on  
> &nbsp;&nbsp;&nbsp;&nbsp;machine  
> &nbsp;&nbsp;&nbsp;&nbsp;\> A. Installing from machine A to machine B is running fine.  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> However, by specifying login\_host parameter this works fine.  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> But, the same parameter is not essential while running from A to B.  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> What could be the scenario?? why is that login\_host parameter is  
> &nbsp;&nbsp;&nbsp;&nbsp;\> required when running from B to A and not vice versa.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;I would be guessing, because you do not give enough information.  
> &nbsp;&nbsp;&nbsp;&nbsp;I presume that your server my.cnf bind only to an IP on machine A,  
> &nbsp;&nbsp;&nbsp;&nbsp;while  
> &nbsp;&nbsp;&nbsp;&nbsp;machine B has a UNIX socket connection, the default MySQL python module  
> &nbsp;&nbsp;&nbsp;&nbsp;uses a UNIX socket connection, while you can override that by using the  
> &nbsp;&nbsp;&nbsp;&nbsp;'login\_host' variable and then the module will use a TCP socket  
> &nbsp;&nbsp;&nbsp;&nbsp;Another possibility is that your user running the Ansible task has a  
> &nbsp;&nbsp;&nbsp;&nbsp;.my.cnf in $HOME which overrides the default host value, so you need to  
> &nbsp;&nbsp;&nbsp;&nbsp;specify the correct one manually
> 
> &nbsp;&nbsp;&nbsp;&nbsp;However this is a wild guess, for a better answer, more information is  
> &nbsp;&nbsp;&nbsp;&nbsp;required.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Thanks in advance,  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Mona G  
> &nbsp;&nbsp;&nbsp;&nbsp;Regards,  
> &nbsp;&nbsp;&nbsp;&nbsp;Tosh.

Mona,

> Dear Tosh,
> 
> Thanks a lot for your response 🙂  
> We are checking on the parameters that you mentioned.  
> Can you list out what more information is required for a better  
> analysis of the same.

Well, Ansible log, MySQL logs and configs  
I do not think it is actually Ansible.  
Remember to sanitized all credentials.

> Regards,  
> Mona G

Regards,  
Tosh.
