Pattu
Pattu

Reputation: 3809

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.

Upvotes: 7

Views: 13801

Answers (2)

Thomas Boulanger
Thomas Boulanger

Reputation: 41

- 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

Upvotes: 4

Palantir
Palantir

Reputation: 24182

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

Upvotes: 10

Related Questions