I want to grant privilege on a db(test_db
) to a user(test_user
) using Ansible. My command is as shown below.
grant all PRIVILEGES on <test_db>.* to <test_user>@'localhost';
How will I execute the command using Ansible.
You could do it like this:
- name: Set mysql user privileges
mysql_user:
name=user_name
priv="dbname.*:ALL"
state=present
Of course you can interpolate variables, like the username, db name, etc...
- name: "Create user {{ user }}"
mysql_user:
name: "{{ user }}"
password: "{{ password }}"
host: localhost
state: present
update_password: on_create
priv: "{{ dbname }}.*:ALL"
login_unix_socket: /var/run/mysqld/mysqld.sock
Solutions works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With