mirror of
https://github.com/geerlingguy/ansible-role-apache
synced 2025-01-10 11:50:18 +01:00
38 lines
1.3 KiB
YAML
38 lines
1.3 KiB
YAML
---
|
|
- 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'
|
|
register: mysql_root_hosts
|
|
changed_when: false
|
|
|
|
# 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.
|
|
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
|
|
|
|
# Has to be after the root password assignment, for idempotency.
|
|
- name: Copy .my.cnf file with root password credentials.
|
|
template:
|
|
src: "user-my.cnf.j2"
|
|
dest: "{{ mysql_user_home }}/.my.cnf"
|
|
owner: root
|
|
group: root
|
|
mode: 0600
|
|
|
|
- name: Get list of hosts for the anonymous user.
|
|
command: mysql -NBe 'SELECT Host FROM mysql.user WHERE User = ""'
|
|
register: mysql_anonymous_hosts
|
|
changed_when: false
|
|
|
|
- name: Remove anonymous MySQL users.
|
|
mysql_user:
|
|
name: ""
|
|
host: "{{ item }}"
|
|
state: absent
|
|
with_items: mysql_anonymous_hosts.stdout_lines
|
|
|
|
- name: Remove MySQL test database.
|
|
mysql_db: "name='test' state=absent"
|