Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible mysql grant

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.

like image 896
Pattu Avatar asked Nov 08 '16 14:11

Pattu


2 Answers

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...

like image 183
Palantir Avatar answered Sep 28 '22 01:09

Palantir


- 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

like image 32
Thomas Boulanger Avatar answered Sep 28 '22 03:09

Thomas Boulanger