From a9859b758732ae8313e9965b7a5f9a7f47608d74 Mon Sep 17 00:00:00 2001 From: Dmitriy Kuts Date: Sun, 18 Aug 2024 23:41:23 +0200 Subject: [PATCH 1/2] Change mysql detection 8.0 to 8. --- tasks/secure-installation.yml | 4 ++-- templates/my.cnf.j2 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/secure-installation.yml b/tasks/secure-installation.yml index eab960b1..e5538c61 100644 --- a/tasks/secure-installation.yml +++ b/tasks/secure-installation.yml @@ -50,7 +50,7 @@ with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}" when: > ((mysql_install_packages | bool) or mysql_root_password_update) - and ('5.7.' in mysql_cli_version.stdout or '8.0.' in mysql_cli_version.stdout) + and ('5.7.' in mysql_cli_version.stdout or '8.' in mysql_cli_version.stdout) # Set root password for MySQL < 5.7.x. - name: Update MySQL root password for localhost root account (< 5.7.x). @@ -61,7 +61,7 @@ with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}" when: > ((mysql_install_packages | bool) or mysql_root_password_update) - and ('5.7.' not in mysql_cli_version.stdout and '8.0.' not in mysql_cli_version.stdout) + and ('5.7.' not in mysql_cli_version.stdout and '8.' not in mysql_cli_version.stdout) # Has to be after the root password assignment, for idempotency. - name: Copy .my.cnf file with root password credentials. diff --git a/templates/my.cnf.j2 b/templates/my.cnf.j2 index ec6fd8ed..d8f289f0 100644 --- a/templates/my.cnf.j2 +++ b/templates/my.cnf.j2 @@ -87,7 +87,7 @@ read_buffer_size = {{ mysql_read_buffer_size }} read_rnd_buffer_size = {{ mysql_read_rnd_buffer_size }} myisam_sort_buffer_size = {{ mysql_myisam_sort_buffer_size }} thread_cache_size = {{ mysql_thread_cache_size }} -{% if '8.0.' not in mysql_cli_version.stdout %} +{% if '8.' not in mysql_cli_version.stdout %} query_cache_type = {{ mysql_query_cache_type }} query_cache_size = {{ mysql_query_cache_size }} query_cache_limit = {{ mysql_query_cache_limit }} @@ -104,7 +104,7 @@ lower_case_table_names = {{ mysql_lower_case_table_names }} event_scheduler = {{ mysql_event_scheduler_state }} # InnoDB settings. -{% if mysql_supports_innodb_large_prefix and '8.0.' not in mysql_cli_version.stdout %} +{% if mysql_supports_innodb_large_prefix and '8.' not in mysql_cli_version.stdout %} innodb_large_prefix = {{ mysql_innodb_large_prefix }} innodb_file_format = {{ mysql_innodb_file_format }} {% endif %} From 76336c25ed54ef4aec9fb3664201a4e827921172 Mon Sep 17 00:00:00 2001 From: Dmitriy Kuts Date: Mon, 19 Aug 2024 00:14:39 +0200 Subject: [PATCH 2/2] For 8.x change auth method --- tasks/secure-installation.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tasks/secure-installation.yml b/tasks/secure-installation.yml index e5538c61..9f0869d2 100644 --- a/tasks/secure-installation.yml +++ b/tasks/secure-installation.yml @@ -41,6 +41,18 @@ # Note: We do not use mysql_user for this operation, as it doesn't always update # the root password correctly. See: https://goo.gl/MSOejW # Set root password for MySQL >= 5.7.x. + +- name: Update MySQL root password for localhost root account (8.x). + ansible.builtin.shell: > + mysql -u root -NBe + "ALTER USER '{{ mysql_root_username }}'@'{{ item }}' + IDENTIFIED WITH caching_sha2_password BY '{{ mysql_root_password }}'; FLUSH PRIVILEGES;" + no_log: "{{ mysql_hide_passwords }}" + with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}" + when: > + ((mysql_install_packages | bool) or mysql_root_password_update) + and ('8.' in mysql_cli_version.stdout) + - name: Update MySQL root password for localhost root account (5.7.x). ansible.builtin.shell: > mysql -u root -NBe @@ -50,7 +62,7 @@ with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}" when: > ((mysql_install_packages | bool) or mysql_root_password_update) - and ('5.7.' in mysql_cli_version.stdout or '8.' in mysql_cli_version.stdout) + and ('5.7.' in mysql_cli_version.stdout) # Set root password for MySQL < 5.7.x. - name: Update MySQL root password for localhost root account (< 5.7.x).