Open ajcanlas-tip opened 3 years ago
@ajcanlas-tip hi, thanks for reporting this.
File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 975, in _get_server_information packet = self._read_packet() File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 669, in _read_packet raise err.InternalError(
Looks like it's not a problem of the module itself but rather as a problem of something behind, e.g. the connector, etc. People get the same error using pymysql (in cases not related to Ansible) and seems that with no solution.
HI @Andersson007 ,
Not sure if this helps it says https://github.com/PyMySQL/PyMySQL/issues/422 here that multi-threaded is not supported thus we might redo the whole thing.
Regards
I am hitting the same error on two Ansible versions
The full traceback is:
File "/tmp/ansible_mysql_db_payload_demn32ts/ansible_mysql_db_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_db.py", line 640, in main
File "/tmp/ansible_mysql_db_payload_demn32ts/ansible_mysql_db_payload.zip/ansible_collections/community/mysql/plugins/module_utils/mysql.py", line 103, in mysql_connect
db_connection = mysql_driver.connect(autocommit=autocommit, **config)
File "/usr/local/lib/python3.6/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 327, in __init__
self.connect()
File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 587, in connect
self._get_server_information()
File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 969, in _get_server_information
packet = self._read_packet()
File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 660, in _read_packet
% (packet_number, self._next_seq_id))
fatal: [example.com]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"ca_cert": null,
"check_hostname": null,
"check_implicit_admin": false,
"client_cert": null,
"client_key": null,
"collation": "",
"config_file": "/root/.my.cnf",
"config_overrides_defaults": false,
"connect_timeout": 30,
"dump_extra_args": null,
"encoding": "",
"force": false,
"hex_blob": false,
"ignore_tables": [],
"login_host": "localhost",
"login_password": null,
"login_port": 3306,
"login_unix_socket": null,
"login_user": null,
"master_data": 0,
"name": [
"test"
],
"quick": true,
"restrict_config_file": false,
"single_transaction": false,
"skip_lock_tables": false,
"state": "absent",
"target": null,
"unsafe_login_password": false,
"use_shell": false
}
},
"msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: Packet sequence number wrong - got 1 expected 0"
}
The credentials are correct as I can connect to the mysql database from the shell, I think the error might not be handled correctly.
@fourstepper thanks for reporting this, what do you mean? (Did you see my previous comment?)
Hi @Andersson007, I have seen it. Perhaps it could be worked around?
Hi @fourstepper , sure, you could try to use mysqlclient https://pypi.org/project/mysqlclient/ or mysqldb driver. If it helps, please let me know
@fourstepper of course, remove pymysql previously
What's interesting also is that when I run the same playbook against a CI container with centos 8 (and systemd), there are no issues with the pymysql driver. It's a bit puzzling. Same Ansible version, same OS (up to date) and the results differ
Yes, it's interesting.
I also experienced this issue - can confirm using mysqlclient
vs pymysql
resolves this on OpenBSD 6.9
@iangregory thanks for the feedback!
With mysqlclient, we get this error instead:
'unable to find /****/.my.cnf. Exception message: (2013, "Lost connection to MySQL server at ''reading initial communication packet'', system error: 0")'
So we are blocked here. Is there any outlook for a fix? Is Ansible reusing a MySQL connection over multiple threads/processes?
@jnm27 do you think if it's related issues? https://stackoverflow.com/questions/5755819/lost-connection-to-mysql-server-at-reading-initial-communication-packet-syste
if anyone tries to run the playbooks where the issue appears with PyMySQL
and the --forks 1
option (the default is 5) and provides the feedback, It would be nice.
@jnm27 ^ could you please do this?
I will go for it @Andersson007
EDIT: Just tried, unfortunately doesn't work :(
@fourstepper thanks!
@fourstepper if it doesn't help, we could in addition add serial: 1
to the playbook
@Andersson007 no bueno either
@fourstepper thanks for the feedback!
yeah, as we can see in the provided traceback, everything seems to happen on the target machine:
The full traceback is:
File "/tmp/ansible_community.mysql.mysql_user_payload_cquoa0hv/ansible_community.mysql.mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py", line 1066, in main
File "/tmp/ansible_community.mysql.mysql_user_payload_cquoa0hv/ansible_community.mysql.mysql_user_payload.zip/ansible_collections/community/mysql/plugins/module_utils/mysql.py", line 103, in mysql_connect
db_connection = mysql_driver.connect(autocommit=autocommit, **config)
File "/usr/lib/python3/dist-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 325, in __init__
self.connect()
File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 598, in connect
self._get_server_information()
File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 975, in _get_server_information
packet = self._read_packet()
File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 669, in _read_packet
raise err.InternalError(
and we don't use any things related to multiprocessing in our modules.. strange. And it's even stranger because, as @fourstepper mentioned, everything works fine in docker. I asked the folks in ansible-community IRC channel. Maybe they have ideas.
It works in CI even for the upstream project that I use, in our CI, but not in my prod :D its kinda sad
https://github.com/geerlingguy/ansible-role-mysql/actions/runs/833828534
Sorry but any updates? Anything we can do to help? What is the next step to investigate?
@jnm27 I ran out of my ideas. The folks in IRC didn't have any ideas too. Anyway it doesn't seem to be problem of the code in this collection. Our modules don't fork anything and, in particular, the code related to PyMySQL, so the object is not shared. And I don't think it's a problem of Ansible-core (which is out of the collection scope) because, as @fourstepper mentioned, same tasks run well in docker. Both mysqlclient and PyMySQL are actively developed. I see an only solution to switch to the first one.
@bmalynovytch @Jorge-Rodriguez do you have anything on your mind?
I encountered the same error today. I tested it on two almost identical machines, one of them got the error but not the other. They are both Ubuntu servers running Mariadb 10.4 with pymysql 0.9.3 installed. Are there any tests I can do that could help you diagnose the issue? Output from the control machine: ansible --version ansible 2.9.21 config file = /etc/ansible/ansible.cfg configured module search path = [u'/home/my_user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/dist-packages/ansible executable location = /usr/bin/ansible python version = 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0]
@beckjkl hi, thanks for the information! And sorry for the late response, was busy with the mysql_role
new module. (BTW if someone is interesting to see it, please review https://github.com/ansible-collections/community.mysql/pull/189).
This case generally looks like something magic. What are the differences of the target machines (because the module itself is executed there). Could you provide the following information for both?
ansible --version
on bothansible_python_interpreter=/path/to/bin/file
variable with python2 and python3 to run the playbookThanks for offering help!
@Andersson007 Hi, I've tried to get as much information as possible:
Ubuntu Version: both Ubuntu 18.04.3 LTS
Kernel version: both the same version root@hostname:~# uname -a Linux hostname 4.15.0-147-generic 151-Ubuntu SMP Fri Jun 18 19:21:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux but the issue already occurred on the previous kernel 4.15.0-142-generic
ansible is not installed on these hosts and I won't install it.
both use python3 by default. With python 2 the problem system had the same error. The working system also didn't work with python 2: "The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required."
@beckjkl thanks for the feedback!
- ansible is not installed on these hosts and I won't install it.
Ah, of course... I woke up feeling a bit underslept today:) Sorry. Now, after 3 coffee I realized that my question was strange:)
Both the systems look configured basically same way. The last point looks a bit suspicious - why the first system doesn't show this error? Obviously the working one uses python3 by default and one of the required libs installed via pip3.
ansible_python_interpreter=
explicitly on the problem machine?mysqlclient
/ mysqldb
is not installed on the working machine via pip3? Maybe there are both. Maybe pip3 list | grep -i mysql
.The last error look really suspicious. Maybe this is the key.
Thanks for your help!
@Andersson007 I've check the problem system again. I remember having some issues when I set up db connections for ansible for the first time. There were some old python2 versions of mysql-client and pymysql still laying around. I removed those. Now both systems only have pymysql installed, but the error persists: root@working-host:~# pip3 list | grep -i mysql PyMySQL (1.0.2)
root@problem-host:~# pip3 list | grep -i mysql PyMySQL (1.0.2)
These are also the only packages installed via pip. The other packages listed by pip were installed via apt.
ansible problem-host -m mysql_replication -a "mode=getmaster login_user=test login_password=..." problem-host | FAILED! => { "changed": false, "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: Packet sequence number wrong - got 1 expected 0" } ansible working-host -m mysql_replication -a "mode=getmaster login_user=test login_password=..." working-host | SUCCESS => { ... "changed": false }
Also explicitly setting ansible_python_interpreter to python3 changes nothing.
@beckjkl so nothing has changed after the purging, right? looks like absolute magic to me as both the systems use same software... I have no ideas then why this happens.
It still looks as something underlying as the function uses high level connector interfaces and the code runs in a single thread on a target machine. As far as I remember we founded that to use mysqlclient
instead of pymysql
should solve the issue.
I got this error too. In slow environment (cloud VM) my script worked perfectly, but on fast VMs from local server I got problem. So I tried to slowdown script on my fast server :)
Script before: ... task "Create replication user" task "Get master status" <-- got error here :(
Script after: ... task "Create replication user" task "Sleep 15s" task "Get master status" <-- no error here :)
This is not ideal solution, but it may help for somebody.
@zlobniyshurik thanks for sharing the workaround!
SUMMARY
failed: [192.168.100.200] (item=127.0.0.1) => {"ansible_loop_var": "item", "changed": false, "item": "127.0.0.1", "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: Packet sequence number wrong - got 1 expected 0"}
Error in running mysql_user to change root password
ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
sample uname -a Linux rpi4b4-0.ajohnsc.com 5.4.0-1022-raspi #25-Ubuntu SMP PREEMPT Thu Oct 15 13:31:49 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux
STEPS TO REPRODUCE
freshly installed mariadb in the server to emulate mysql_secure_installation
EXPECTED RESULTS
expected to emulate mysql_secure_installation
ACTUAL RESULTS
It detected that it uses multithreading but it uses only one thread