geerlingguy / ansible-role-mysql

Ansible Role - MySQL
https://galaxy.ansible.com/geerlingguy/mysql/
MIT License
1.05k stars 862 forks source link

Module fails to interact with database due to missing python 2 module #438

Closed thorian93 closed 3 years ago

thorian93 commented 3 years ago

Python interpreter: Python 2

Affected OS:

I took the role as is and ran it against the server which got me the following message:

TASK [geerlingguy.mysql : Remove MySQL test database.] **************************************************************
fatal: [server]: FAILED! => {"changed": false, "msg": "The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required."}

As far as I understand the role should make sure the proper Python modules are installed, right? I build my own role some time ago and took care of that but I can not figure out, why this does not work here. Any hint to what I am doing wrong?

thorian93 commented 3 years ago

To elaborate: This does not happen on Ubuntu 20.04.

1977er commented 3 years ago

As a quick&dirty workaround you can do something like mysql_packages: ['mariadb-server', 'python-pymysql', 'python3-pymysql'] in your variable section.

geerlingguy commented 3 years ago

Hmm... also see https://github.com/geerlingguy/ansible-role-mysql/issues/445

On RHEL 8, python3-PyMySQL is in the dependencies installed.

On Debian 10, I only have default-mysql-server. Maybe installing python3-pymysql would fix this?

geerlingguy commented 3 years ago

Hmm... that might not be the best way. Also, the mysql collection is reverting the change that started producing errors on RHEL 7 systems.

thorian93 commented 3 years ago

I might be totally of course here, but would it be an idea to define those prerequisites in the OS-specific variable files once they become necessary? I do that in some of my roles and it works arguably good. Also you already have some of those files in use. That way you can go with the defaults as long as they work but you are able to set specific packages for specific distributions.

thorian93 commented 3 years ago

I just realized that this issue depends on the python interpreter. Forcing Ansible to use Python 3 solves the issue. Apparently the problem is Python 2 and the related packages. Is this even something you want to address @geerlingguy or do you see that as out of scope for your role?

geerlingguy commented 3 years ago

@thorian93 - Since this seems to be something that could be very environment/OS-dependent, I'd rather not try to solve the python package problem in this role (unless it's something in this role that is causing the issue).

baradhili commented 3 years ago

No forcing ansible to use python3 doesn't fix this.. it is showing up in community.mysql as well.. for some reason ansible can't see pymysql - even if it is asked to install it itself.

thorian93 commented 3 years ago

Interesting, for me it worked. I will keep an eye on it and update if I find anything worth mentioning.

stale[bot] commented 3 years ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] commented 3 years ago

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

daraul commented 2 years ago

Setting my python interpreter doesn't seem to fix this issue for me. If I do "molecule converge" twice, the 2nd run will work. The 1st will fail. I'm a little confused about why this happens, though.

daraul commented 2 years ago

Setting the mysql_packages variable as @1977er recommended seems to work, but now I get another error at "geerlingguy.mysql : Remove MySQL test database.". This is on ubuntu:18.04

daraul commented 2 years ago

I figured out a solution that works for me. I had to install python3.6 manually (or, in prepare.yml). Then I define that as my interpreter: ansible_python_interpreter: /usr/bin/python3.6. I tested with python3.8 and ended up with the same issue.