|
4 | 4 | msg: 'ERROR - you have to change default mysql_root_password' |
5 | 5 | when: mysql_root_password == '-----====>SetR00tPa$$wordH3r3!!!<====-----' |
6 | 6 |
|
7 | | -- name: Root password is present |
8 | | - mysql_user: |
| 7 | +- name: ensure that the root password is present |
| 8 | + community.mysql.mysql_user: |
9 | 9 | name: 'root' |
10 | 10 | host_all: true |
11 | 11 | password: '{{ mysql_root_password | mandatory }}' |
|
19 | 19 | mode: '0400' |
20 | 20 | tags: my_cnf |
21 | 21 |
|
22 | | -- name: Test database is absent |
23 | | - mysql_db: |
| 22 | +- name: ensure that the test database is absent |
| 23 | + community.mysql.mysql_db: |
24 | 24 | name: test |
25 | 25 | state: absent |
26 | 26 | login_unix_socket: "{{ login_unix_socket | default(omit) }}" |
27 | 27 | when: mysql_remove_test_database |
28 | 28 |
|
29 | | -- name: Anonymous users are absent |
30 | | - mysql_user: |
| 29 | +- name: ensure that anonymous users are absent |
| 30 | + community.mysql.mysql_user: |
31 | 31 | name: '' |
32 | 32 | state: absent |
33 | 33 | host_all: true |
34 | 34 | login_unix_socket: "{{ login_unix_socket | default(omit) }}" |
35 | 35 | when: mysql_remove_anonymous_users |
36 | 36 |
|
37 | | -- name: Remove remote root |
| 37 | +- name: ensure that root can only login from localhost |
38 | 38 | community.mysql.mysql_query: |
39 | 39 | query: |
40 | | - - DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1') |
| 40 | + - DELETE |
| 41 | + FROM mysql.user |
| 42 | + WHERE USER='root' |
| 43 | + AND HOST NOT IN ('localhost', |
| 44 | + '127.0.0.1', |
| 45 | + '::1') |
41 | 46 | login_unix_socket: "{{ login_unix_socket | default(omit) }}" |
42 | 47 | when: mysql_remove_remote_root |
| 48 | + |
| 49 | +- name: get all users that have no password or authentication_string on MySQL version >= 5.7.6 |
| 50 | + community.mysql.mysql_query: |
| 51 | + query: |
| 52 | + - SELECT GROUP_CONCAT(USER, '@', HOST SEPARATOR ', ') AS users |
| 53 | + FROM mysql.user |
| 54 | + WHERE (length(authentication_string)=0 |
| 55 | + OR authentication_string="") |
| 56 | + AND USER NOT IN ('mysql.sys', |
| 57 | + 'mysqlxsys', |
| 58 | + 'mariadb.sys'); |
| 59 | + login_unix_socket: "{{ login_unix_socket | default(omit) }}" |
| 60 | + register: mysql_users_wo_passwords_or_auth_string |
| 61 | + when: |
| 62 | + - mysql_version.version.full is version('5.7.6', '>=') |
| 63 | + |
| 64 | +- name: get all users that have no password on MySQL version < 5.7.6 |
| 65 | + community.mysql.mysql_query: |
| 66 | + query: |
| 67 | + - SELECT GROUP_CONCAT(USER, '@', HOST SEPARATOR ', ') AS users |
| 68 | + FROM mysql.user |
| 69 | + WHERE (length(password)=0 |
| 70 | + OR password="") |
| 71 | + AND (length(authentication_string)=0 |
| 72 | + OR authentication_string="") |
| 73 | + AND USER NOT IN ('mysql.sys', |
| 74 | + 'mysqlxsys', |
| 75 | + 'mariadb.sys'); |
| 76 | + login_unix_socket: "{{ login_unix_socket | default(omit) }}" |
| 77 | + register: mysql_users_wo_passwords |
| 78 | + when: |
| 79 | + - mysql_version.version.full is version('5.7.6', '<') |
| 80 | + |
| 81 | +- name: create a fact for users without password or authentication_string |
| 82 | + set_fact: |
| 83 | + users_wo_auth: "{{ mysql_users_wo_passwords_or_auth_string.query_result.0.0 | community.general.json_query('users') }}" |
| 84 | + when: |
| 85 | + - mysql_users_wo_passwords_or_auth_string.query_result is defined |
| 86 | + - mysql_users_wo_passwords_or_auth_string.query_result != "" # noqa empty-string-compare |
| 87 | + |
| 88 | +- name: create a fact for users without password |
| 89 | + set_fact: |
| 90 | + users_wo_auth: "{{ mysql_users_wo_passwords.query_result.0.0 | community.general.json_query('users') }}" |
| 91 | + when: |
| 92 | + - mysql_users_wo_passwords.query_result is defined |
| 93 | + - mysql_users_wo_passwords.query_result != "" # noqa empty-string-compare |
| 94 | + |
| 95 | +- name: ensure that there are no users without password or authentication_string |
| 96 | + community.mysql.mysql_query: |
| 97 | + query: |
| 98 | + - "DROP USER {{ users_wo_auth }}" |
| 99 | + login_unix_socket: "{{ login_unix_socket | default(omit) }}" |
| 100 | + when: |
| 101 | + - users_wo_auth is defined |
| 102 | + - users_wo_auth != "" # noqa empty-string-compare |
0 commit comments