ansible-roles/mysql/tasks/datadir.yml
David Prevot fc692cf65b
All checks were successful
gitea/ansible-roles/pipeline/head This commit looks good
Allow more --check runs
Use “when: not ansible_check_mode” or “when <file>.stat.exists or not
ansible_check_mode” in order to provide a meaningful diff if possible.

This is an improvement from the previously reverted commit
1728eaee68.
2022-12-21 18:05:41 +01:00

47 lines
1.1 KiB
YAML

---
- block:
- name: "Is {{ mysql_custom_datadir }} present ?"
stat:
path: "{{ mysql_custom_datadir }}"
check_mode: no
register: mysql_custom_datadir_test
- name: "read the real datadir"
command: readlink -f /var/lib/mysql
changed_when: False
check_mode: no
register: mysql_current_real_datadir_test
tags:
- mysql
when: mysql_custom_datadir | length > 0
- block:
- name: MySQL is stopped
service:
name: mysql
state: stopped
- name: Move MySQL datadir to {{ mysql_custom_datadir }}
command: mv {{ mysql_current_real_datadir_test.stdout }} {{ mysql_custom_datadir }}
args:
creates: "{{ mysql_custom_datadir }}"
- name: Symlink {{ mysql_custom_datadir }} to /var/lib/mysql
file:
src: "{{ mysql_custom_datadir }}"
dest: '/var/lib/mysql'
state: link
- name: MySQL is started
service:
name: mysql
state: started
tags:
- mysql
when:
- mysql_custom_datadir | length > 0
- mysql_custom_datadir != mysql_current_real_datadir_test.stdout
- not mysql_custom_datadir_test.stat.exists
- not ansible_check_mode