mirror of
https://github.com/aljazceru/ansible-role-mysql.git
synced 2026-01-04 06:54:27 +01:00
Merge pull request #131 from geerlingguy/fix-root-pw-57
Update secure-installation for correct root password in 5.7+.
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
---
|
||||
- name: Get MySQL version.
|
||||
command: 'mysql --version'
|
||||
register: mysql_cli_version
|
||||
changed_when: false
|
||||
|
||||
- name: Disallow root login remotely
|
||||
command: 'mysql -NBe "{{ item }}"'
|
||||
with_items:
|
||||
- DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')
|
||||
changed_when: False
|
||||
changed_when: false
|
||||
|
||||
- name: Get list of hosts for the root user.
|
||||
command: mysql -NBe 'SELECT Host FROM mysql.user WHERE User = "root" ORDER BY (Host="localhost") ASC'
|
||||
@@ -13,12 +18,21 @@
|
||||
|
||||
# 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
|
||||
- name: Update MySQL root password for localhost root account.
|
||||
# Set root password for MySQL >= 5.7.x.
|
||||
- name: Update MySQL root password for localhost root account (5.7.x).
|
||||
shell: >
|
||||
mysql -u root -NBe
|
||||
'ALTER USER "{{ mysql_root_username }}"@"{{ item }}" IDENTIFIED WITH mysql_native_password BY "{{ mysql_root_password }}";'
|
||||
with_items: "{{ mysql_root_hosts.stdout_lines }}"
|
||||
when: ((mysql_install_packages | bool) or mysql_root_password_update) 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).
|
||||
shell: >
|
||||
mysql -u root -NBe
|
||||
'SET PASSWORD FOR "{{ mysql_root_username }}"@"{{ item }}" = PASSWORD("{{ mysql_root_password }}");'
|
||||
with_items: "{{ mysql_root_hosts.stdout_lines }}"
|
||||
when: mysql_install_packages | bool or mysql_root_password_update
|
||||
when: ((mysql_install_packages | bool) or mysql_root_password_update) and ('5.7.' 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.
|
||||
|
||||
Reference in New Issue
Block a user