# Create MariaDB users and grant privileges

**URL:** <https://forum.ansible.com/t/create-mariadb-users-and-grant-privileges/45915>\
**Category:** Get Help\
**Created:** [June 13, 2026, 2:54pm UTC](https://forum.ansible.com/t/create-mariadb-users-and-grant-privileges/45915 "2026-06-13T14:54:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![microlinux](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/microlinux/32/2968_2.png) [@microlinux](https://forum.ansible.com/u/microlinux)\
**Post date:** [June 13, 2026, 2:54pm UTC](https://forum.ansible.com/t/create-mariadb-users-and-grant-privileges/45915/1 "2026-06-13T14:54:48Z")

</div>

Hi,

I have the following task in an Ansible playbook :

```auto
- name: Create MariaDB users and grant privileges
  community.mysql.mysql_user:
    name: "{{item.user}}"
    password: "{{item.password}}"
    priv: "{{item.name}}.*:ALL"
    login_unix_socket: /var/run/mysqld/mysqld.sock
    column_case_sensitive: true
    state: present
  loop: "{{mariadb_databases}}"
  no_log: true

```

The playbook sets up a MariaDB database server, creates initial MariaDB users, etc.

Now the task in itself works. The problem is, it’s not idempotent, e. g. it reports a change every time the playbook is executed.

Any idea how to make this task idempotent ?

---

<div class="post-metadata">

**Author:** ![jon-nfc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jon-nfc/32/10748_2.png) [@jon-nfc](https://forum.ansible.com/u/jon-nfc)\
**Post date:** [June 13, 2026, 3:04pm UTC](https://forum.ansible.com/t/create-mariadb-users-and-grant-privileges/45915/2 "2026-06-13T15:04:46Z")

</div>

> [@microlinux](#):
>
> Any idea how to make this task idempotent ?

According to the docs it has full support ([ansible.mysql.mysql\_user module – Adds or removes a user from a MySQL or MariaDB database — Ansible Community Documentation](https://docs.ansible.com/projects/ansible/latest/collections/ansible/mysql/mysql_user_module.html#attributes)).

With that said I’d turn logging back on and check whats reporting as different.

---

<div class="post-metadata">

**Author:** ![Kevinwincott](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kevinwincott](https://forum.ansible.com/u/Kevinwincott)\
**Post date:** [June 17, 2026, 9:27am UTC](https://forum.ansible.com/t/create-mariadb-users-and-grant-privileges/45915/3 "2026-06-17T09:27:24Z")

</div>

this works for me without issue on MariaDB:

- name: Create database users  
ansible.mysql.mysql\_user:  
name: xxx  
password: xxx  
priv: “_._:ALL,GRANT”  
state: present  
login\_unix\_socket: /run/mysqld/mysqld.sock
