ansible-collections / community.mysql

MySQL Ansible Collection
https://galaxy.ansible.com/ui/repo/published/community/mysql/
Other
99 stars 86 forks source link

mysql_user: fails to connect (not reading .my.cnf file?) #215

Closed mario-pranjic closed 2 years ago

mario-pranjic commented 3 years ago
SUMMARY

Ansible code, environment and target server did not change. However, on re-run of Ansible code with latest version, I am getting:

TASK [prepare : Update MariaDB root password for all root accounts] **************************************************************************************************************************
failed: [repa.malizeko.com] (item=repa) => {"ansible_loop_var": "item", "changed": false, "item": "repa", "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)\")"}
failed: [repa.malizeko.com] (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: (2003, \"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)\")"}
failed: [repa.malizeko.com] (item=::1) => {"ansible_loop_var": "item", "changed": false, "item": "::1", "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)\")"}
failed: [repa.malizeko.com] (item=localhost) => {"ansible_loop_var": "item", "changed": false, "item": "localhost", "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)\")"}
ISSUE TYPE
COMPONENT NAME

mysql_user

ANSIBLE VERSION
ansible [core 2.11.4] 
  config file = /home/mario/repositories/vps_ubuntu/ansible.cfg
  configured module search path = ['/home/mario/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/ansible/lib/python3.9/site-packages/ansible
  ansible collection location = /home/mario/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/ansible/bin/ansible
  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
  jinja version = 3.0.1
  libyaml = True
COLLECTION VERSION
Collection                    Version
----------------------------- -------
amazon.aws                    1.5.0  
ansible.netcommon             2.4.0  
ansible.posix                 1.3.0  
ansible.utils                 2.4.0  
ansible.windows               1.7.2  
arista.eos                    2.2.0  
awx.awx                       19.2.2 
azure.azcollection            1.9.0  
check_point.mgmt              2.0.0  
chocolatey.chocolatey         1.1.0  
cisco.aci                     2.0.0  
cisco.asa                     2.0.3  
cisco.intersight              1.0.17 
cisco.ios                     2.4.0  
cisco.iosxr                   2.4.0  
cisco.meraki                  2.4.2  
cisco.mso                     1.2.0  
cisco.nso                     1.0.3  
cisco.nxos                    2.5.1  
cisco.ucs                     1.6.0  
cloudscale_ch.cloud           2.2.0  
community.aws                 1.5.0  
community.azure               1.0.0  
community.crypto              1.9.2  
community.digitalocean        1.9.0  
community.docker              1.9.1  
community.fortios             1.0.0  
community.general             3.6.0  
community.google              1.0.0  
community.grafana             1.2.1  
community.hashi_vault         1.3.2  
community.hrobot              1.1.1  
community.kubernetes          1.2.1  
community.kubevirt            1.0.0  
community.libvirt             1.0.2  
community.mongodb             1.3.1  
community.mysql               2.1.1  
community.network             3.0.0  
community.okd                 1.1.2  
community.postgresql          1.4.0  
community.proxysql            1.2.0  
community.rabbitmq            1.1.0  
community.routeros            1.2.0  
community.skydive             1.0.0  
community.sops                1.1.0  
community.vmware              1.13.0 
community.windows             1.6.0  
community.zabbix              1.4.0  
containers.podman             1.7.0  
cyberark.conjur               1.1.0  
cyberark.pas                  1.0.7  
dellemc.enterprise_sonic      1.1.0  
dellemc.openmanage            3.6.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.11.0 
fortinet.fortimanager         2.1.3  
fortinet.fortios              2.1.2  
frr.frr                       1.0.3  
gluster.gluster               1.0.1  
google.cloud                  1.0.2  
hetzner.hcloud                1.6.0  
hpe.nimble                    1.1.3  
ibm.qradar                    1.0.3  
infinidat.infinibox           1.2.4  
inspur.sm                     1.3.0  
junipernetworks.junos         2.5.0  
kubernetes.core               1.2.1  
mellanox.onyx                 1.0.0  
netapp.aws                    21.6.0 
netapp.azure                  21.8.1 
netapp.cloudmanager           21.9.0 
netapp.elementsw              21.6.1 
netapp.ontap                  21.10.0
netapp.um_info                21.7.0 
netapp_eseries.santricity     1.2.13 
netbox.netbox                 3.1.1  
ngine_io.cloudstack           2.1.0  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.0  
openstack.cloud               1.5.0  
openvswitch.openvswitch       2.0.0  
ovirt.ovirt                   1.6.2  
purestorage.flasharray        1.10.0 
purestorage.flashblade        1.6.0  
sensu.sensu_go                1.12.0 
servicenow.servicenow         1.0.6  
splunk.es                     1.0.2  
t_systems_mms.icinga_director 1.21.1 
theforeman.foreman            2.2.0  
vyos.vyos                     2.5.1  
wti.remote                    1.0.1  
CONFIGURATION
CALLBACKS_ENABLED(/home/mario/repositories/vps_ubuntu/ansible.cfg) = ['timer']
DEFAULT_HOST_LIST(/home/mario/repositories/vps_ubuntu/ansible.cfg) = ['/home/mario/repositories/vps_ubuntu/inventory']
DEFAULT_MANAGED_STR(/home/mario/repositories/vps_ubuntu/ansible.cfg) = This file is managed by Ansible - do not edit here!
DEFAULT_REMOTE_USER(/home/mario/repositories/vps_ubuntu/ansible.cfg) = root
DEFAULT_VAULT_PASSWORD_FILE(/home/mario/repositories/vps_ubuntu/ansible.cfg) = /home/mario/get-vault-pass-vps.sh
DEPRECATION_WARNINGS(/home/mario/repositories/vps_ubuntu/ansible.cfg) = False
RETRY_FILES_ENABLED(/home/mario/repositories/vps_ubuntu/ansible.cfg) = False
OS / ENVIRONMENT

Ansible controler:

$ uname -a
Linux asgard 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) x86_64 GNU/Linux
$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Ansible target node:

$ uname -a
Linux repa 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$at /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
STEPS TO REPRODUCE

Run task defined below.

Presumption is we have .my.cnf file in place

EXPECTED RESULTS

Task was not failing until recently with latest ansible version. No changes in ansible code, or on target server.

ACTUAL RESULTS
TASK [prepare : Update MariaDB root password for all root accounts] **************************************************************************************************************************
task path: /home/mario/repositories/vps_ubuntu/roles/prepare/tasks/mariadb.yml:21
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp `"&& mkdir "` echo $HOME/.ansible/tmp/ansible-tmp-1631347845.0932448-224190-31781721072322 `" && echo ansible-tmp-1631347845.0932448-224190-31781721072322="` echo $HOME/.ansible/tmp/ansible-tmp-1631347845.0932448-224190-31781721072322 `" ) && sleep 0'"'"''
<repa.malizeko.com> (0, b'ansible-tmp-1631347845.0932448-224190-31781721072322=/root/.ansible/tmp/ansible-tmp-1631347845.0932448-224190-31781721072322\n', b'')
redirecting (type: modules) ansible.builtin.mysql_user to community.mysql.mysql_user
Using module file /usr/local/ansible/lib/python3.9/site-packages/ansible_collections/community/mysql/plugins/modules/mysql_user.py
<repa.malizeko.com> PUT /home/mario/.ansible/tmp/ansible-local-224139aettrw9u/tmpj5s0r7iq TO /root/.ansible/tmp/ansible-tmp-1631347845.0932448-224190-31781721072322/AnsiballZ_mysql_user.py
<repa.malizeko.com> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 '[repa.malizeko.com]'
<repa.malizeko.com> (0, b'sftp> put /home/mario/.ansible/tmp/ansible-local-224139aettrw9u/tmpj5s0r7iq /root/.ansible/tmp/ansible-tmp-1631347845.0932448-224190-31781721072322/AnsiballZ_mysql_user.py\n', b'')
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1631347845.0932448-224190-31781721072322/ /root/.ansible/tmp/ansible-tmp-1631347845.0932448-224190-31781721072322/AnsiballZ_mysql_user.py && sleep 0'"'"''
<repa.malizeko.com> (0, b'', b'')
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 -tt repa.malizeko.com '/bin/sh -c '"'"'/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1631347845.0932448-224190-31781721072322/AnsiballZ_mysql_user.py && sleep 0'"'"''
<repa.malizeko.com> (1, b'\r\n{"failed": true, "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \\"Can\'t connect to MySQL server on \'localhost\' ([Errno 111] Connection refused)\\")", "exception": "  File \\"/tmp/ansible_mysql_user_payload_ks8ui83b/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py\\", line 1209, in main\\n  File \\"/tmp/ansible_mysql_user_payload_ks8ui83b/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/module_utils/mysql.py\\", line 103, in mysql_connect\\n    db_connection = mysql_driver.connect(autocommit=autocommit, **config)\\n  File \\"/usr/lib/python3/dist-packages/pymysql/__init__.py\\", line 94, in Connect\\n    return Connection(*args, **kwargs)\\n  File \\"/usr/lib/python3/dist-packages/pymysql/connections.py\\", line 325, in __init__\\n    self.connect()\\n  File \\"/usr/lib/python3/dist-packages/pymysql/connections.py\\", line 630, in connect\\n    raise exc\\n", "invocation": {"module_args": {"name": "root", "host": "repa", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "priv": "*.*:ALL,GRANT", "user": "root", "login_host": "localhost", "login_port": 3306, "config_file": "/root/.my.cnf", "connect_timeout": 30, "encrypted": false, "host_all": false, "state": "present", "append_privs": false, "check_implicit_admin": false, "update_password": "always", "sql_log_bin": true, "login_user": null, "login_password": null, "login_unix_socket": null, "client_cert": null, "client_key": null, "ca_cert": null, "check_hostname": null, "tls_requires": null, "plugin": null, "plugin_hash_string": null, "plugin_auth_string": null, "resource_limits": null}}}\r\n', b'Shared connection to repa.malizeko.com closed.\r\n')
<repa.malizeko.com> Failed to connect to the host via ssh: Shared connection to repa.malizeko.com closed.
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1631347845.0932448-224190-31781721072322/ > /dev/null 2>&1 && sleep 0'"'"''
<repa.malizeko.com> (0, b'', b'')
The full traceback is:
  File "/tmp/ansible_mysql_user_payload_ks8ui83b/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py", line 1209, in main
  File "/tmp/ansible_mysql_user_payload_ks8ui83b/ansible_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 630, in connect
    raise exc
failed: [repa.malizeko.com] (item=repa) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "append_privs": false,
            "ca_cert": null,
            "check_hostname": null,
            "check_implicit_admin": false,
            "client_cert": null,
            "client_key": null,
            "config_file": "/root/.my.cnf",
            "connect_timeout": 30,
            "encrypted": false,
            "host": "repa",
            "host_all": false,
            "login_host": "localhost",
            "login_password": null,
            "login_port": 3306,
            "login_unix_socket": null,
            "login_user": null,
            "name": "root",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "plugin": null,
            "plugin_auth_string": null,
            "plugin_hash_string": null,
            "priv": "*.*:ALL,GRANT",
            "resource_limits": null,
            "sql_log_bin": true,
            "state": "present",
            "tls_requires": null,
            "update_password": "always",
            "user": "root"
        }
    },
    "item": "repa",
    "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)\")"
}
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp `"&& mkdir "` echo $HOME/.ansible/tmp/ansible-tmp-1631347846.071434-224190-263249047900915 `" && echo ansible-tmp-1631347846.071434-224190-263249047900915="` echo $HOME/.ansible/tmp/ansible-tmp-1631347846.071434-224190-263249047900915 `" ) && sleep 0'"'"''
<repa.malizeko.com> (0, b'ansible-tmp-1631347846.071434-224190-263249047900915=/root/.ansible/tmp/ansible-tmp-1631347846.071434-224190-263249047900915\n', b'')
redirecting (type: modules) ansible.builtin.mysql_user to community.mysql.mysql_user
Using module file /usr/local/ansible/lib/python3.9/site-packages/ansible_collections/community/mysql/plugins/modules/mysql_user.py
<repa.malizeko.com> PUT /home/mario/.ansible/tmp/ansible-local-224139aettrw9u/tmpz64uqn0w TO /root/.ansible/tmp/ansible-tmp-1631347846.071434-224190-263249047900915/AnsiballZ_mysql_user.py
<repa.malizeko.com> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 '[repa.malizeko.com]'
<repa.malizeko.com> (0, b'sftp> put /home/mario/.ansible/tmp/ansible-local-224139aettrw9u/tmpz64uqn0w /root/.ansible/tmp/ansible-tmp-1631347846.071434-224190-263249047900915/AnsiballZ_mysql_user.py\n', b'')
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1631347846.071434-224190-263249047900915/ /root/.ansible/tmp/ansible-tmp-1631347846.071434-224190-263249047900915/AnsiballZ_mysql_user.py && sleep 0'"'"''
<repa.malizeko.com> (0, b'', b'')
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 -tt repa.malizeko.com '/bin/sh -c '"'"'/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1631347846.071434-224190-263249047900915/AnsiballZ_mysql_user.py && sleep 0'"'"''
<repa.malizeko.com> (1, b'\r\n{"failed": true, "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \\"Can\'t connect to MySQL server on \'localhost\' ([Errno 111] Connection refused)\\")", "exception": "  File \\"/tmp/ansible_mysql_user_payload_g8i9ovsi/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py\\", line 1209, in main\\n  File \\"/tmp/ansible_mysql_user_payload_g8i9ovsi/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/module_utils/mysql.py\\", line 103, in mysql_connect\\n    db_connection = mysql_driver.connect(autocommit=autocommit, **config)\\n  File \\"/usr/lib/python3/dist-packages/pymysql/__init__.py\\", line 94, in Connect\\n    return Connection(*args, **kwargs)\\n  File \\"/usr/lib/python3/dist-packages/pymysql/connections.py\\", line 325, in __init__\\n    self.connect()\\n  File \\"/usr/lib/python3/dist-packages/pymysql/connections.py\\", line 630, in connect\\n    raise exc\\n", "invocation": {"module_args": {"name": "root", "host": "127.0.0.1", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "priv": "*.*:ALL,GRANT", "user": "root", "login_host": "localhost", "login_port": 3306, "config_file": "/root/.my.cnf", "connect_timeout": 30, "encrypted": false, "host_all": false, "state": "present", "append_privs": false, "check_implicit_admin": false, "update_password": "always", "sql_log_bin": true, "login_user": null, "login_password": null, "login_unix_socket": null, "client_cert": null, "client_key": null, "ca_cert": null, "check_hostname": null, "tls_requires": null, "plugin": null, "plugin_hash_string": null, "plugin_auth_string": null, "resource_limits": null}}}\r\n', b'Shared connection to repa.malizeko.com closed.\r\n')
<repa.malizeko.com> Failed to connect to the host via ssh: Shared connection to repa.malizeko.com closed.
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1631347846.071434-224190-263249047900915/ > /dev/null 2>&1 && sleep 0'"'"''
<repa.malizeko.com> (0, b'', b'')
The full traceback is:
  File "/tmp/ansible_mysql_user_payload_g8i9ovsi/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py", line 1209, in main
  File "/tmp/ansible_mysql_user_payload_g8i9ovsi/ansible_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 630, in connect
    raise exc
failed: [repa.malizeko.com] (item=127.0.0.1) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "append_privs": false,
            "ca_cert": null,
            "check_hostname": null,
            "check_implicit_admin": false,
            "client_cert": null,
            "client_key": null,
            "config_file": "/root/.my.cnf",
            "connect_timeout": 30,
            "encrypted": false,
            "host": "127.0.0.1",
            "host_all": false,
            "login_host": "localhost",
            "login_password": null,
            "login_port": 3306,
            "login_unix_socket": null,
            "login_user": null,
            "name": "root",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "plugin": null,
            "plugin_auth_string": null,
            "plugin_hash_string": null,
            "priv": "*.*:ALL,GRANT",
            "resource_limits": null,
            "sql_log_bin": true,
            "state": "present",
            "tls_requires": null,
            "update_password": "always",
            "user": "root"
        }
    },
    "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: (2003, \"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)\")"
}
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp `"&& mkdir "` echo $HOME/.ansible/tmp/ansible-tmp-1631347846.8811464-224190-40292024069944 `" && echo ansible-tmp-1631347846.8811464-224190-40292024069944="` echo $HOME/.ansible/tmp/ansible-tmp-1631347846.8811464-224190-40292024069944 `" ) && sleep 0'"'"''
<repa.malizeko.com> (0, b'ansible-tmp-1631347846.8811464-224190-40292024069944=/root/.ansible/tmp/ansible-tmp-1631347846.8811464-224190-40292024069944\n', b'')
redirecting (type: modules) ansible.builtin.mysql_user to community.mysql.mysql_user
Using module file /usr/local/ansible/lib/python3.9/site-packages/ansible_collections/community/mysql/plugins/modules/mysql_user.py
<repa.malizeko.com> PUT /home/mario/.ansible/tmp/ansible-local-224139aettrw9u/tmp_bre6kq8 TO /root/.ansible/tmp/ansible-tmp-1631347846.8811464-224190-40292024069944/AnsiballZ_mysql_user.py
<repa.malizeko.com> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 '[repa.malizeko.com]'
<repa.malizeko.com> (0, b'sftp> put /home/mario/.ansible/tmp/ansible-local-224139aettrw9u/tmp_bre6kq8 /root/.ansible/tmp/ansible-tmp-1631347846.8811464-224190-40292024069944/AnsiballZ_mysql_user.py\n', b'')
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1631347846.8811464-224190-40292024069944/ /root/.ansible/tmp/ansible-tmp-1631347846.8811464-224190-40292024069944/AnsiballZ_mysql_user.py && sleep 0'"'"''
<repa.malizeko.com> (0, b'', b'')
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 -tt repa.malizeko.com '/bin/sh -c '"'"'/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1631347846.8811464-224190-40292024069944/AnsiballZ_mysql_user.py && sleep 0'"'"''
<repa.malizeko.com> (1, b'\r\n{"failed": true, "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \\"Can\'t connect to MySQL server on \'localhost\' ([Errno 111] Connection refused)\\")", "exception": "  File \\"/tmp/ansible_mysql_user_payload_x2o2en7l/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py\\", line 1209, in main\\n  File \\"/tmp/ansible_mysql_user_payload_x2o2en7l/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/module_utils/mysql.py\\", line 103, in mysql_connect\\n    db_connection = mysql_driver.connect(autocommit=autocommit, **config)\\n  File \\"/usr/lib/python3/dist-packages/pymysql/__init__.py\\", line 94, in Connect\\n    return Connection(*args, **kwargs)\\n  File \\"/usr/lib/python3/dist-packages/pymysql/connections.py\\", line 325, in __init__\\n    self.connect()\\n  File \\"/usr/lib/python3/dist-packages/pymysql/connections.py\\", line 630, in connect\\n    raise exc\\n", "invocation": {"module_args": {"name": "root", "host": "::1", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "priv": "*.*:ALL,GRANT", "user": "root", "login_host": "localhost", "login_port": 3306, "config_file": "/root/.my.cnf", "connect_timeout": 30, "encrypted": false, "host_all": false, "state": "present", "append_privs": false, "check_implicit_admin": false, "update_password": "always", "sql_log_bin": true, "login_user": null, "login_password": null, "login_unix_socket": null, "client_cert": null, "client_key": null, "ca_cert": null, "check_hostname": null, "tls_requires": null, "plugin": null, "plugin_hash_string": null, "plugin_auth_string": null, "resource_limits": null}}}\r\n', b'Shared connection to repa.malizeko.com closed.\r\n')
<repa.malizeko.com> Failed to connect to the host via ssh: Shared connection to repa.malizeko.com closed.
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1631347846.8811464-224190-40292024069944/ > /dev/null 2>&1 && sleep 0'"'"''
<repa.malizeko.com> (0, b'', b'')
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
The full traceback is:
  File "/tmp/ansible_mysql_user_payload_x2o2en7l/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py", line 1209, in main
  File "/tmp/ansible_mysql_user_payload_x2o2en7l/ansible_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 630, in connect
    raise exc
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp `"&& mkdir "` echo $HOME/.ansible/tmp/ansible-tmp-1631347847.7256777-224190-61679230288505 `" && echo ansible-tmp-1631347847.7256777-224190-61679230288505="` echo $HOME/.ansible/tmp/ansible-tmp-1631347847.7256777-224190-61679230288505 `" ) && sleep 0'"'"''
failed: [repa.malizeko.com] (item=::1) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "append_privs": false,
            "ca_cert": null,
            "check_hostname": null,
            "check_implicit_admin": false,
            "client_cert": null,
            "client_key": null,
            "config_file": "/root/.my.cnf",
            "connect_timeout": 30,
            "encrypted": false,
            "host": "::1",
            "host_all": false,
            "login_host": "localhost",
            "login_password": null,
            "login_port": 3306,
            "login_unix_socket": null,
            "login_user": null,
            "name": "root",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "plugin": null,
            "plugin_auth_string": null,
            "plugin_hash_string": null,
            "priv": "*.*:ALL,GRANT",
            "resource_limits": null,
            "sql_log_bin": true,
            "state": "present",
            "tls_requires": null,
            "update_password": "always",
            "user": "root"
        }
    },
    "item": "::1",
    "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)\")"
}
<repa.malizeko.com> (0, b'ansible-tmp-1631347847.7256777-224190-61679230288505=/root/.ansible/tmp/ansible-tmp-1631347847.7256777-224190-61679230288505\n', b'')
redirecting (type: modules) ansible.builtin.mysql_user to community.mysql.mysql_user
Using module file /usr/local/ansible/lib/python3.9/site-packages/ansible_collections/community/mysql/plugins/modules/mysql_user.py
<repa.malizeko.com> PUT /home/mario/.ansible/tmp/ansible-local-224139aettrw9u/tmpnjppiw4h TO /root/.ansible/tmp/ansible-tmp-1631347847.7256777-224190-61679230288505/AnsiballZ_mysql_user.py
<repa.malizeko.com> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 '[repa.malizeko.com]'
<repa.malizeko.com> (0, b'sftp> put /home/mario/.ansible/tmp/ansible-local-224139aettrw9u/tmpnjppiw4h /root/.ansible/tmp/ansible-tmp-1631347847.7256777-224190-61679230288505/AnsiballZ_mysql_user.py\n', b'')
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1631347847.7256777-224190-61679230288505/ /root/.ansible/tmp/ansible-tmp-1631347847.7256777-224190-61679230288505/AnsiballZ_mysql_user.py && sleep 0'"'"''
<repa.malizeko.com> (0, b'', b'')
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 -tt repa.malizeko.com '/bin/sh -c '"'"'/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1631347847.7256777-224190-61679230288505/AnsiballZ_mysql_user.py && sleep 0'"'"''
<repa.malizeko.com> (1, b'\r\n{"failed": true, "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \\"Can\'t connect to MySQL server on \'localhost\' ([Errno 111] Connection refused)\\")", "exception": "  File \\"/tmp/ansible_mysql_user_payload_43llyeu4/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py\\", line 1209, in main\\n  File \\"/tmp/ansible_mysql_user_payload_43llyeu4/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/module_utils/mysql.py\\", line 103, in mysql_connect\\n    db_connection = mysql_driver.connect(autocommit=autocommit, **config)\\n  File \\"/usr/lib/python3/dist-packages/pymysql/__init__.py\\", line 94, in Connect\\n    return Connection(*args, **kwargs)\\n  File \\"/usr/lib/python3/dist-packages/pymysql/connections.py\\", line 325, in __init__\\n    self.connect()\\n  File \\"/usr/lib/python3/dist-packages/pymysql/connections.py\\", line 630, in connect\\n    raise exc\\n", "invocation": {"module_args": {"name": "root", "host": "localhost", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "priv": "*.*:ALL,GRANT", "user": "root", "login_host": "localhost", "login_port": 3306, "config_file": "/root/.my.cnf", "connect_timeout": 30, "encrypted": false, "host_all": false, "state": "present", "append_privs": false, "check_implicit_admin": false, "update_password": "always", "sql_log_bin": true, "login_user": null, "login_password": null, "login_unix_socket": null, "client_cert": null, "client_key": null, "ca_cert": null, "check_hostname": null, "tls_requires": null, "plugin": null, "plugin_hash_string": null, "plugin_auth_string": null, "resource_limits": null}}}\r\n', b'Shared connection to repa.malizeko.com closed.\r\n')
<repa.malizeko.com> Failed to connect to the host via ssh: Shared connection to repa.malizeko.com closed.
<repa.malizeko.com> ESTABLISH SSH CONNECTION FOR USER: root
<repa.malizeko.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/mario/.ansible/cp/6c6e62bbf3 repa.malizeko.com '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1631347847.7256777-224190-61679230288505/ > /dev/null 2>&1 && sleep 0'"'"''
<repa.malizeko.com> (0, b'', b'')
The full traceback is:
  File "/tmp/ansible_mysql_user_payload_43llyeu4/ansible_mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py", line 1209, in main
  File "/tmp/ansible_mysql_user_payload_43llyeu4/ansible_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 630, in connect
    raise exc
failed: [repa.malizeko.com] (item=localhost) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "append_privs": false,
            "ca_cert": null,
            "check_hostname": null,
            "check_implicit_admin": false,
            "client_cert": null,
            "client_key": null,
            "config_file": "/root/.my.cnf",
            "connect_timeout": 30,
            "encrypted": false,
            "host": "localhost",
            "host_all": false,
            "login_host": "localhost",
            "login_password": null,
            "login_port": 3306,
            "login_unix_socket": null,
            "login_user": null,
            "name": "root",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "plugin": null,
            "plugin_auth_string": null,
            "plugin_hash_string": null,
            "priv": "*.*:ALL,GRANT",
            "resource_limits": null,
            "sql_log_bin": true,
            "state": "present",
            "tls_requires": null,
            "update_password": "always",
            "user": "root"
        }
    },
    "item": "localhost",
    "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)\")"
}
mario-pranjic commented 3 years ago

I verified on target server, .my.cnf file is in place and root user can connect by using it.

# ls -l /root/.my.cnf 
-rw------- 1 root root 99 Sep 11 08:39 /root/.my.cnf

root@repa:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 549407
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Tried to explicitly set it in task - didn't help. I also tried to use login_user and login_password instead - didn't help.

mario-pranjic commented 3 years ago

Target database is mariadb. Seems like root auth is required to go via unix socket.

Solution: adding following parameter to mysql_user task:

login_unix_socket: "/var/run/mysqld/mysqld.sock"

This resolves the issue for mysqluser as well ass for other mysql modules when it comes to root auth.

This issue can be closed.

Andersson007 commented 3 years ago

@mario-pranjic hi, welcome to the project and thank you for the issue and the solution! Let's keep it open for some time. If there are similar issues appear, we should definitely investigate the code.

Ah, you're using MariaDB. I released community.mysql 2.2.0-a1 a month ago that is available on Galaxy here. Would you like to contribute more and help testing it. It would be much appreciated. It contains a new module called mysql_role. Help needed because we unfortunately don't test against MariaDB in CI. I checked it locally but I'm not a DBA, so my testing might not be complete. I also moved a lot of code from mysql_user to share it with mysql_role, so would be nice to test mysql_user as well.

The doc for mysql_role is available in the DOCUMENTATION and EXAMPLES sections here.

mario-pranjic commented 3 years ago

Hi Andrew,

I will certianly take a look. Can test both on mariadb and mysql.

Andersson007 commented 3 years ago

Hi Mario, great, thanks! We'll be waiting for your feedback then!

rsicart commented 2 years ago

Just an interesting link about "Connection refused" error messages: https://dev.mysql.com/doc/refman/8.0/en/can-not-connect-to-server.html

Any updates about this issue @mario-pranjic @Andersson007 ?

chriscroome commented 2 years ago

I've found that on Debian Bullseye with MariaDB the community.mysql modules cannot be used with either a login_password or a config_file when the root authentication plugin is set to mysql_native_password -- they simply fail.

I've a MariaDB Galaxy role that has tasks to set the root auth plugin to a password when using a socket and tasks to set the root auth plugin to a socket when using a password, the existing auth method is queried using a Bash facts.d script.

All the tasks use the command and shell modules when the auth plugin is mysql_native_password and the community.mysql modules when the auth plugin is unix_socket.

I haven't tested this when there are multiple root auth plugins (but it might work!) and I haven't recently tested this role with Debian versions older than Bullseye, however the 1.9.1 version doesn't use community.mysql modules and probably works on older versions, older versions of this role have been used when upgrading servers from Debian Jessie and Stretch.

Andersson007 commented 2 years ago

@rsicart no updates from me and thank you for the link!

@chriscroome thank you for the feedback!

chriscroome commented 2 years ago

@Andersson007 sorry I wasn't clear, everything works fine with socket authentication, the problem is if you disable socket authentication then neither specifying a valid /root/.my.cnf file or the password works.

I've not worked with RedHat based distros for many years so I'm sorry that I don't know what the situation is with these modules and those distros these days.

chriscroome commented 2 years ago

I don't think the problem I have described is a separate issue from the one above, this issue explains the bug, but if it would help if I created a separate issue with an example I could.

chriscroome commented 2 years ago

This issue appears to be related, #262, I think you will find that the root user can only connect using a socket if tests like these are run with MariaDB.

Andersson007 commented 2 years ago

@chriscroome thanks for the info! I'll put the help_wanted label as i don't know when i can find enough time to dive into it.

Andersson007 commented 2 years ago

two things. Any ideas on 1) can it relate to the server-side recent changes? Or 2) can it relate to our code changes (i.e. someone introduced a bug)? To figure out this, can someone try to use older Ansible version, say Ansible 2.9 and community.mysql 1.0.0?

help with p.2 would be much appreciated

chriscroome commented 2 years ago

@Andersson007 I'll look at 2. but it might not be until next week.

Andersson007 commented 2 years ago

@Andersson007 I'll look at 2. but it might not be until next week.

@chriscroome sure, no rush, thanks!

chriscroome commented 2 years ago

@Andersson007 sorry this took longer that planned, I've created a GitLab repo with a CI configuration that installs several Ansible versions on Debian Bullseye and then tests switching between password, file and socket authentication to create a new MariaDB user using using mysql_user and the results are written to a file, Ansible was installed as follows:

python3 -m pip install ansible==2.9.27

python3 -m pip install ansible-base==2.10.17
ansible-galaxy collection install community.mysql:==1.2.0

python3 -m pip install ansible-core==2.11.11
ansible-galaxy collection install community.mysql:==1.4.6

python3 -m pip install ansible-core==2.12.5
ansible-galaxy collection install community.mysql:==2.3.7

python3 -m pip install ansible-core==2.13.0
ansible-galaxy collection install community.mysql:==3.2.1

The results didn't general any errors, which isn't what I was expecting! So either I have made some mistakes in the tests or there isn't an issue here...

Ansible 2.9.27 with MariaDB 10.5.15

chriscroome commented 2 years ago

I've added a create database test as well and still it appears that everything is working without issues, the latest results:

Ansible 2.9.27 with MariaDB 10.5.15

chriscroome commented 2 years ago

I suspect that the reason I thought there was a problem here is related to the issue with defaults files without [client] sections.

Andersson007 commented 2 years ago

@chriscroome ah, i missed your comments since https://github.com/ansible-collections/community.mysql/issues/215#issuecomment-1132183832, sorry, maybe was on PTO..

Thanks for the investigation and feedback!

So, i think we could close the issue then?

chriscroome commented 2 years ago

Yes it is fine to close this issue as far as I'm concerned.

Andersson007 commented 2 years ago

Thank you folks! If needed we can re-open it

vp0122 commented 10 months ago

The full traceback is: File "/tmp/ansible_community.mysql.mysql_db_payloadh3x3ryg/ansible_community.mysql.mysql_db_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_db.py", line 639, in main File "/tmp/ansible_community.mysql.mysql_db_payloadh3x3ryg/ansible_community.mysql.mysql_db_payload.zip/ansible_collections/community/mysql/plugins/module_utils/mysql.py", line 106, in mysql_connect db_connection = mysql_driver.connect(autocommit=autocommit, **config) File "/openstack/venvs/utility-25.5.1.dev6/lib/python3.8/site-packages/pymysql/connections.py", line 353, in init self.connect() File "/openstack/venvs/utility-25.5.1.dev6/lib/python3.8/site-packages/pymysql/connections.py", line 664, in connect raise exc failed: [infra1_keystone_container-a297f966 -> infra1_utility_container-ef743dfd(172.16.105.197)] (item={'name': 'keystone', 'users': [{'username': 'keystone', 'password': '1940fa859922fb2053369aa42ea11b8cd0a35060f0b184d32b'}]}) => { "ansible_loop_var": "item", "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": "172.16.104.99", "login_password": null, "login_port": 3306, "login_unix_socket": null, "login_user": null, "master_data": 0, "name": [ "keystone" ], "quick": true, "restrict_config_file": false, "single_transaction": false, "skip_lock_tables": false, "state": "present", "target": null, "unsafe_login_password": false, "use_shell": false } }, "item": { "name": "keystone", "users": [ { "password": "1940fa859922fb2053369aa42ea11b8cd0a35060f0b184d32b", "username": "keystone" } ] }, "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: (2003, \"Can't connect to MySQL server on '172.16.104.99' ([Errno 113] No route to host)\")" }

Hi Can somebody help me with this issue? I was in the middle of OpenStack-Ansible setup-openstack.yml Thanks in advance