简体   繁体   中英

ansible mysql "check_implicit_admin" (without root user password)

I try to create a database with ansible and a user with database permissions.

The current mysql setup is the basic config after installation on ubuntu 20.04. mysql server: 8.0.24

A root mysql password is not setup and I can access mysql without password

sudo mysql ...

Why ansible force to use a password?

check_implicit_admin sould work in this case?

Ansible configuration:

- name: Create a new database with name 'db_example'
  community.mysql.mysql_db:
  check_implicit_admin: yes
  login_user: root
  login_password: ''
  name: db_example
  state: present

- name: Create database user with name 'userx' and database privileges
  community.mysql.mysql_user:
  check_implicit_admin: yes
  login_user: root
  login_password: ''
  name: userx
  password: userx_password
  priv:
  'db_exampmle.*': 'ALL,GRANT'
  state: present

Ansible error:

TASK [Create a new database with name 'db_example'] **********************************************************************************
fatal: [localhost]: 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: (1698, \"Access denied for user 'root'@'localhost'\")"}

I tried to set a password with:

sudo mysql -u root --execute="SET PASSWORD FOR 'root'@'localhost' = 'pass';"

Same error message in ansible, changed value: login_password: 'pass'

MySQL allows admin access when root but only when the client is using a socket connection.

If you add login_unix_socket: "/run/mysqld/mysqld.sock" it'll work from the ansible client the same way as the mysql client. That's the socket used in Ubuntu 20.04, other systems or versions might differ.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM