Ansible 不会将权限从 USAGE 更改为 GRANT ALL

2021-11-11 00:00:00 ansible ansible-playbook mariadb mysql

我使用以下 ansible 任务将所有权限授予所有数据库.

I used following ansible task to GRANT ALL privilege to all databases.

- name: create new user {{ db_user }} with all privilege
  mysql_user: name="{{ db_user }}"
              password="{{ db_password }}"
              append_privs=yes
              priv=*.*:ALL,GRANT state=present

但是当我在 mysql(mariadb) 上运行 show grants for 'dbuser'@'XX.XX.XX.XX'; 它显示我跟随.

but when I run show grants for 'dbuser'@'XX.XX.XX.XX'; on mysql(mariadb) it shows me following.

GRANT USAGE ON *.* TO 'dbuser'@'XX.XX.XX.XX' IDENTIFIED BY PASSWORD '*A7AD1ECBCD787B8CABE6A58AEA652A8B3CF5035BA82'

如何使用 ansible 将此 USAGE 更改为 GRANT ALL?

How to change this USAGE to GRANT ALL using ansible?

推荐答案

默认情况下 mysql_user 使用 localhost 主机部分创建用户.
因此,您的任务使用 GRANT ALL 创建了 dbuser@localhost.
如果您需要其他主机,请为模块设置 host=XX.XX.XX.XX 参数.
从 2.1 开始修改权限时也有 host_all=yes 可用.

By default mysql_user creates users with localhost host portion.
So your task created dbuser@localhost with GRANT ALL.
If you need another host, set host=XX.XX.XX.XX parameter for the module.
Also there is host_all=yes available since 2.1 when modifying permissions.

相关文章