2015-07-12 17:15:59 +07:00
|
|
|
---
|
|
|
|
|
2015-08-11 15:22:58 +07:00
|
|
|
- hosts: all
|
2019-04-16 18:55:38 +07:00
|
|
|
gather_facts: false
|
|
|
|
pre_tasks:
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- name: SETUP | Get facts
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.setup:
|
2019-04-16 18:55:38 +07:00
|
|
|
register: s
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- name: DEBUG | Show facts
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.debug:
|
2019-04-16 18:55:38 +07:00
|
|
|
var: s
|
2015-08-11 15:22:58 +07:00
|
|
|
tasks:
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- name: APT | Install some packages
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.apt:
|
2019-04-16 18:55:38 +07:00
|
|
|
name: "{{ p }}"
|
2021-09-02 23:17:54 +07:00
|
|
|
update_cache: true
|
2019-04-16 18:55:38 +07:00
|
|
|
cache_valid_time: 3600
|
|
|
|
vars:
|
2021-09-02 23:17:54 +07:00
|
|
|
p: ['ca-certificates', 'curl', 'strace', 'rsyslog', 'vim']
|
|
|
|
|
|
|
|
- name: SERVICE | Ensure rsyslog is started
|
|
|
|
ansible.builtin.service:
|
|
|
|
name: rsyslog
|
|
|
|
state: started
|
2015-08-09 02:34:17 +07:00
|
|
|
|
2015-08-11 15:22:58 +07:00
|
|
|
- hosts: master
|
2015-08-09 02:34:17 +07:00
|
|
|
roles:
|
|
|
|
- ../../
|
2015-08-11 15:22:58 +07:00
|
|
|
tasks:
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- name: COPY | Deploy first dump
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.copy:
|
2019-04-16 18:55:38 +07:00
|
|
|
src: import1.sql
|
|
|
|
dest: /tmp/import1.sql
|
2021-09-02 23:17:54 +07:00
|
|
|
mode: 0644
|
|
|
|
owner: root
|
|
|
|
group: root
|
2015-08-11 15:22:58 +07:00
|
|
|
register: c
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- name: MYSQL_DB | Import first dump
|
2021-09-02 23:17:54 +07:00
|
|
|
community.mysql.mysql_db:
|
2019-04-16 18:55:38 +07:00
|
|
|
name: "{{ item }}"
|
|
|
|
state: import
|
|
|
|
target: /tmp/import1.sql
|
2021-09-02 23:17:54 +07:00
|
|
|
login_unix_socket: "{{ mariadb_socket }}"
|
2019-04-12 14:38:42 +07:00
|
|
|
loop: ['testrepl', 'norepl']
|
2015-08-11 15:22:58 +07:00
|
|
|
when: c.changed
|
2021-09-02 23:17:54 +07:00
|
|
|
tags:
|
|
|
|
- skip_ansible_lint
|
2015-08-09 02:34:17 +07:00
|
|
|
|
2015-08-11 15:22:58 +07:00
|
|
|
- hosts: slave
|
2017-06-28 21:15:44 +07:00
|
|
|
pre_tasks:
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2017-06-28 21:15:44 +07:00
|
|
|
- name: SHELL | Get master IP
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.shell: set -o pipefail && getent hosts {{ ansible_hostname | replace ('slave', 'master') }} | cut -d ' ' -f 1
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
2017-06-28 21:15:44 +07:00
|
|
|
register: ip
|
|
|
|
changed_when: false
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- name: SET_FACT | Apply some configuration
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.set_fact:
|
2018-03-18 00:47:35 +07:00
|
|
|
# MariaDB don't read /etc/hosts (from vagrant host plugin)
|
2018-03-17 23:28:54 +07:00
|
|
|
mariadb_replication_host: "{{ ip.stdout }}"
|
2017-06-28 21:15:44 +07:00
|
|
|
# Need this to use vagrant 'delegate_to'
|
2018-03-17 23:28:54 +07:00
|
|
|
mariadb_slave_import_from: "{{ ansible_hostname | replace ('slave', 'master') }}"
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2015-08-09 02:34:17 +07:00
|
|
|
roles:
|
|
|
|
- ../../
|
2015-08-11 15:22:58 +07:00
|
|
|
tasks:
|
2019-12-29 01:02:41 +07:00
|
|
|
|
|
|
|
- block:
|
|
|
|
|
2021-09-02 23:17:54 +07:00
|
|
|
- name: COPY | Deploy dump
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: import2.sql
|
|
|
|
dest: /tmp/import2.sql
|
|
|
|
mode: 0644
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
|
|
|
register: c
|
|
|
|
|
|
|
|
- name: MYSQL_DB | Import another dump
|
|
|
|
community.mysql.mysql_db:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: import
|
|
|
|
target: /tmp/import2.sql
|
|
|
|
login_unix_socket: "{{ mariadb_socket }}"
|
|
|
|
loop: ['testrepl', 'norepl']
|
|
|
|
when: c.changed
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2018-03-17 23:28:54 +07:00
|
|
|
delegate_to: "{{ mariadb_slave_import_from }}"
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- name: MYSQL_REPLICATION | Get slave infos
|
2021-09-02 23:17:54 +07:00
|
|
|
community.mysql.mysql_replication:
|
2019-04-16 18:55:38 +07:00
|
|
|
mode: getslave
|
2017-06-28 21:15:44 +07:00
|
|
|
register: slave
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- name: FAIL | if slave threads are not running
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.fail:
|
2019-04-16 18:55:38 +07:00
|
|
|
msg: "Slave issue"
|
2017-06-28 21:15:44 +07:00
|
|
|
when: slave.Slave_IO_Running != 'Yes' or slave.Slave_SQL_Running != 'Yes'
|
2015-08-09 02:34:17 +07:00
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- hosts: galera
|
2017-06-28 21:15:44 +07:00
|
|
|
pre_tasks:
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2021-09-02 23:17:54 +07:00
|
|
|
- name: APT_REPOSITORY | Force galera-3 on Buster + MariaDB from Debian repository (prevent crashes)
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
mariadb_galera_package_name: 'galera-3'
|
|
|
|
when: ansible_distribution_release == 'buster' and mariadb_origin == 'default'
|
|
|
|
|
2019-04-16 18:55:38 +07:00
|
|
|
- name: SET_FACT | Apply some configuration
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.set_fact:
|
2019-08-07 22:41:45 +07:00
|
|
|
mariadb_galera_primary_node: '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-{{ mariadb_origin }}-galera-1'
|
2019-04-16 18:55:38 +07:00
|
|
|
mariadb_wsrep_node_address: "{{ '127.0.0.1' if is_docker else ansible_eth1.ipv4.address }}"
|
2019-12-29 01:02:41 +07:00
|
|
|
|
2016-09-23 16:40:35 +07:00
|
|
|
roles:
|
|
|
|
- ../../
|