Skip to content

fix: ensure MySQL Users task works for MySQL 8.4 #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions tasks/users.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
---
- name: Ensure MySQL users are present.
mysql_user:
- name: Get MySQL version
block:
- name: Run mysql --version
ansible.builtin.command: "{{ mysql_daemon }} --version"
register: mysql_cli_version
changed_when: false
check_mode: false

- name: Extract MySQL version
ansible.builtin.set_fact:
mysql_cli_version: >-
{{ (mysql_cli_version.stdout | split(' '))[('mariadb' in (mysql_cli_version.stdout | lower)) | ternary(5, 3)][:-1] }}

- name: Ensure MySQL users are present (Linux, MySQL >= 8.0).
community.mysql.mysql_user:
name: "{{ item.name }}"
host: "{{ item.host | default('localhost') }}"
plugin: "caching_sha2_password"
plugin_auth_string: "{{ item.password }}"
salt: "{{ lookup('password', '/dev/null length=20 chars=ascii_letters,digits') }}"
priv: "{{ item.priv | default('*.*:USAGE') }}"
state: "{{ item.state | default('present') }}"
append_privs: "{{ item.append_privs | default(false) }}"
encrypted: "{{ item.encrypted | default(false) }}"
column_case_sensitive: "{{ item.case_sensitive | default(false) }}"
update_password: "{{ item.update_password | default('always') }}"
with_items: "{{ mysql_users }}"
no_log: "{{ mysql_hide_passwords }}"
when: mysql_cli_version is version('8.0', '>=')

- name: Ensure MySQL users are present (Linux, MySQL == 5.7).
community.mysql.mysql_user:
name: "{{ item.name }}"
host: "{{ item.host | default('localhost') }}"
password: "{{ item.password }}"
Expand All @@ -12,3 +42,4 @@
update_password: "{{ item.update_password | default('always') }}"
with_items: "{{ mysql_users }}"
no_log: "{{ mysql_hide_passwords }}"
when: mysql_cli_version is version('5.7', '==')