ansible-mysql/tasks/replication/slave/import_data.yml

85 lines
2.2 KiB
YAML
Raw Normal View History

---
- name: FILE | Create SSH client dir
file:
path: "{{ ansible_env.HOME }}/.ssh"
state: directory
mode: 0700
- name: OPENSSH_KEYPAIR | Create SSH key
openssh_keypair:
path: "{{ ansible_env.HOME }}/.ssh/id_rsa"
register: gen_ssh
- block:
- name: AUTHORIZED_KEY | Auth slave to backup host
authorized_key:
user: "{{ mariadb_backup_user }}"
state: present
key: "{{ gen_ssh.public_key }}"
- name: FILE | Create backup directory
file:
path: "{{ mariadb_backup_dir }}"
state: directory
- name: COMMAND | Prepare backup another server
command: "mariabackup --backup -u root --target-dir={{ mariadb_backup_dir }}"
args:
creates: "{{ mariadb_backup_dir }}/xtrabackup_info"
register: backup
- name: SHELL | Dump
shell: "mariabackup --prepare --target-dir={{ mariadb_backup_dir }}"
when: backup.changed
register: prep
changed_when: "'This target seems to be not prepared yet' in prep.stderr"
2018-03-17 23:28:54 +07:00
delegate_to: "{{ mariadb_slave_import_from }}"
- name: MYSQL_VARIABLES | Get datadir
mysql_variables:
variable: datadir
register: datadir
- name: SET_FACT | Get MariaDB datadir
set_fact:
2018-03-18 00:28:56 +07:00
mariadb_datadir: "{{ datadir.msg }}"
2018-03-18 00:47:35 +07:00
- name: SERVICE | Stop MariaDB before importing data
2018-03-18 00:28:56 +07:00
service:
name: mysql
state: stopped
# TODO: add an "ignore warning"
2018-03-17 23:28:54 +07:00
- name: COMMAND | Sync backup to slave - TODO remove vagrant as static user (see why mariadb_backup_user is not working)
2018-03-18 00:28:56 +07:00
shell: "sudo -E rsync --rsync-path='sudo rsync' -a -e 'ssh -o StrictHostKeyChecking=no' {{ mariadb_backup_user }}@{{ mariadb_slave_import_from }}:{{ mariadb_backup_dir }}/ {{ mariadb_datadir }}/"
become: no
- name: FILE | Re-apply owner
2018-03-18 00:28:56 +07:00
file:
path: "{{ mariadb_datadir }}"
state: directory
owner: mysql
group: mysql
recurse: yes
- name: SHELL | Remove InnoDB redo logs
shell: "rm -f {{ mariadb_datadir }}/ib_logfile*"
args:
removes: "{{ mariadb_datadir }}/ib_logfile0"
warn: false
2018-03-18 00:28:56 +07:00
- name: SERVICE | Start MariaDB
service:
name: mysql
state: started
- name: FILE | Delete dump
file:
path: "{{ mariadb_backup_dir }}"
state: absent
2018-03-17 23:28:54 +07:00
delegate_to: "{{ mariadb_slave_import_from }}"
when: mariadb_slave_import_flush_dump