mirror of
https://github.com/HanXHX/ansible-mysql.git
synced 2026-02-24 10:13:30 +07:00
Rename mysql_ -> mariadb_
This commit is contained in:
@@ -3,19 +3,19 @@
|
||||
- name: FETCH | Get /etc/mysql/debian.cnf on master
|
||||
fetch: >
|
||||
src=/etc/mysql/debian.cnf
|
||||
dest=/tmp/{{ mysql_slave_import_from }}/debian.cnf
|
||||
dest=/tmp/{{ mariadb_slave_import_from }}/debian.cnf
|
||||
flat=yes
|
||||
changed_when: false
|
||||
delegate_to: "{{ mysql_slave_import_from }}"
|
||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||
|
||||
- name: LOCAL_ACTION FILE | Secure fetched file
|
||||
local_action: file path=/tmp/{{ mysql_slave_import_from }}/debian.cnf mode=0600
|
||||
local_action: file path=/tmp/{{ mariadb_slave_import_from }}/debian.cnf mode=0600
|
||||
become: no
|
||||
|
||||
- name: COPY | Fetched file to /etc/mysql/debian.cnf
|
||||
copy: >
|
||||
src=/tmp/{{ mysql_slave_import_from }}/debian.cnf
|
||||
src=/tmp/{{ mariadb_slave_import_from }}/debian.cnf
|
||||
dest=/etc/mysql/debian.cnf
|
||||
owner=root group=root mode=0600
|
||||
notify: restart mysql
|
||||
notify: restart mariadb
|
||||
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
# Doc: https://www.percona.com/doc/percona-xtrabackup/2.1/howtos/recipes_ibkx_gtid.html
|
||||
- name: WAIT_FOR | source data (prevent rsync bug) - TODO find another hack
|
||||
wait_for: host={{ mysql_slave_import_from }} port=22
|
||||
wait_for: host={{ mariadb_slave_import_from }} port=22
|
||||
|
||||
- name: COMMAND | Prepare backup another server
|
||||
command: innobackupex --no-timestamp {{ mysql_backup_dir }} creates={{ mysql_backup_dir }}
|
||||
delegate_to: "{{ mysql_slave_import_from }}"
|
||||
command: innobackupex --no-timestamp {{ mariadb_backup_dir }} creates={{ mariadb_backup_dir }}
|
||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||
register: backup
|
||||
|
||||
- name: SHELL | Dump
|
||||
shell: innobackupex --apply-log {{ mysql_backup_dir }}
|
||||
delegate_to: "{{ mysql_slave_import_from }}"
|
||||
shell: innobackupex --apply-log {{ mariadb_backup_dir }}
|
||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||
when: backup.changed
|
||||
|
||||
- name: FILE | Remove mysql db from backup
|
||||
file: path={{ mysql_backup_dir }}/mysql state=absent
|
||||
delegate_to: "{{ mysql_slave_import_from }}"
|
||||
when: backup.changed and not mysql_slave_replicate_mysqldb
|
||||
file: path={{ mariadb_backup_dir }}/mysql state=absent
|
||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||
when: backup.changed and not mariadb_slave_replicate_mysqldb
|
||||
|
||||
- name: MYSQL_VARIABLES | Get datadir
|
||||
mysql_variables: variable=datadir
|
||||
@@ -25,20 +25,20 @@
|
||||
|
||||
- name: SET_FACT | related to mysql datadir
|
||||
set_fact:
|
||||
mysql_mysql_datadir: "{{ datadir.msg }}"
|
||||
mysql_binlog_info: "{{ datadir.msg }}/xtrabackup_binlog_info"
|
||||
mariadb_mariadb_datadir: "{{ datadir.msg }}"
|
||||
mariadb_binlog_info: "{{ datadir.msg }}/xtrabackup_binlog_info"
|
||||
|
||||
- name: SERVICE | Stop MySQL before importing data
|
||||
service: name=mysql state=stopped
|
||||
|
||||
# TODO: add an "ignore warning"
|
||||
- name: COMMAND | Sync backup to slave - TODO remove vagrant as static user (see why mysql_backup_user is not working)
|
||||
shell: "sudo -E rsync --rsync-path='sudo rsync' -a -e 'ssh -o StrictHostKeyChecking=no' {{ mysql_backup_user }}@{{ mysql_slave_import_from }}:{{ mysql_backup_dir }}/ {{ mysql_mysql_datadir }}/"
|
||||
- name: COMMAND | Sync backup to slave - TODO remove vagrant as static user (see why mariadb_backup_user is not working)
|
||||
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_mariadb_datadir }}/"
|
||||
become: no
|
||||
|
||||
- name: FILE | Re-apply owner
|
||||
file: >
|
||||
path={{ mysql_mysql_datadir }}
|
||||
path={{ mariadb_mariadb_datadir }}
|
||||
state=directory
|
||||
owner=mysql
|
||||
group=mysql
|
||||
@@ -48,25 +48,25 @@
|
||||
service: name=mysql state=started
|
||||
|
||||
- name: SHELL | Get master_log_file
|
||||
command: awk '{ print $1 }' {{ mysql_binlog_info }}
|
||||
command: awk '{ print $1 }' {{ mariadb_binlog_info }}
|
||||
register: master_log_file
|
||||
|
||||
- name: SHELL | Get master_log_pos
|
||||
command: awk '{ print $2 }' {{ mysql_binlog_info }}
|
||||
command: awk '{ print $2 }' {{ mariadb_binlog_info }}
|
||||
register: master_log_pos
|
||||
|
||||
- name: SHELL | Get master GTID
|
||||
command: awk '{ print $3 }' {{ mysql_binlog_info }}
|
||||
command: awk '{ print $3 }' {{ mariadb_binlog_info }}
|
||||
register: master_gtid
|
||||
|
||||
- name: SET_FACT | master_log_file
|
||||
set_fact:
|
||||
mysql_master_log_file: "{{ master_log_file.stdout }}"
|
||||
mysql_master_log_pos: "{{ master_log_pos.stdout }}"
|
||||
mysql_master_gtid: "{{ master_gtid.stdout }}"
|
||||
mariadb_master_log_file: "{{ master_log_file.stdout }}"
|
||||
mariadb_master_log_pos: "{{ master_log_pos.stdout }}"
|
||||
mariadb_master_gtid: "{{ master_gtid.stdout }}"
|
||||
|
||||
- name: FILE | Delete dump
|
||||
file: path={{ mysql_backup_dir }} state=absent
|
||||
delegate_to: "{{ mysql_slave_import_from }}"
|
||||
when: mysql_slave_import_flush_dump
|
||||
file: path={{ mariadb_backup_dir }} state=absent
|
||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||
when: mariadb_slave_import_flush_dump
|
||||
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
- name: MYSQL_REPLICATION | Configure master host
|
||||
mysql_replication: >
|
||||
mode=changemaster
|
||||
master_host={{ mysql_replication_host }}
|
||||
master_port={{ mysql_replication_port }}
|
||||
master_user={{ mysql_replication_user }}
|
||||
master_password={{ mysql_replication_password }}
|
||||
master_host={{ mariadb_replication_host }}
|
||||
master_port={{ mariadb_replication_port }}
|
||||
master_user={{ mariadb_replication_user }}
|
||||
master_password={{ mariadb_replication_password }}
|
||||
|
||||
- name: MYSQL_REPLICATION | Change master
|
||||
mysql_replication: >
|
||||
mode=changemaster
|
||||
master_log_file={{ mysql_master_log_file }}
|
||||
master_log_pos={{ mysql_master_log_pos }}
|
||||
when: mysql_master_log_file is defined and mysql_master_log_pos is defined
|
||||
master_log_file={{ mariadb_master_log_file }}
|
||||
master_log_pos={{ mariadb_master_log_pos }}
|
||||
when: mariadb_master_log_file is defined and mariadb_master_log_pos is defined
|
||||
|
||||
- name: MYSQL_REPLICATION | Start slave
|
||||
mysql_replication: mode=startslave
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
- name: AUTHORIZED_KEY | Auth slave to backup host
|
||||
authorized_key:
|
||||
user: "{{ mysql_backup_user }}"
|
||||
user: "{{ mariadb_backup_user }}"
|
||||
state: present
|
||||
key: "{{ pub_key.stdout }}"
|
||||
delegate_to: "{{ mysql_slave_import_from }}"
|
||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||
become: yes
|
||||
|
||||
Reference in New Issue
Block a user