kolla-ansible/ansible/roles/mariadb/tasks/lookup_cluster.yml
Radosław Piliszek 9f14ad651a Fix multiple issues with MariaDB handling
These affected both deploy (and reconfigure) and upgrade
resulting in WSREP issues, failed deploys or need to
recover the cluster.

This patch makes sure k-a does not abruptly terminate
nodes to break cluster.
This is achieved by cleaner separation between stages
(bootstrap, restart current, deploy new) and 3 phases
for restarts (to keep the quorum).

Upgrade actions, which operate on a healthy cluster,
went to its section.

Service restart was refactored.

We no longer rely on the master/slave distinction as
all nodes are masters in Galera.

Closes-bug: #1857908
Closes-bug: #1859145
Change-Id: I83600c69141714fc412df0976f49019a857655f5
2020-01-15 20:15:09 +01:00

66 lines
2.3 KiB
YAML

---
- name: Create MariaDB volume
become: true
kolla_docker:
action: "create_volume"
common_options: "{{ docker_common_options }}"
name: "mariadb"
register: mariadb_volume
- name: Divide hosts by their MariaDB volume availability
group_by:
key: mariadb_had_volume_{{ mariadb_volume is not changed }}
- name: Establish whether the cluster has already existed
set_fact:
mariadb_cluster_exists: "{{ groups.mariadb_had_volume_True is defined }}"
- block:
- name: Check MariaDB service port liveness
wait_for:
host: "{{ api_interface_address }}"
port: "{{ mariadb_port }}"
connect_timeout: 1
timeout: 10
search_regex: "MariaDB"
register: check_mariadb_port_liveness
ignore_errors: yes
- name: Divide hosts by their MariaDB service port liveness
group_by:
key: mariadb_port_alive_{{ check_mariadb_port_liveness is success }}
- block:
- name: Check MariaDB service WSREP sync status
become: true
command: >-
docker exec {{ mariadb_service.container_name }}
mysql -uroot -p{{ database_password }}
--silent --skip-column-names
-e 'SHOW STATUS LIKE "wsrep_local_state_comment"'
changed_when: false
register: check_mariadb_sync_status
no_log: true
# NOTE(yoctozepto): this is extracted separately to properly escape
# the TAB character which likes to go wrong due to interaction between
# Python/Ansible/Jinja2/YAML, the way below works
- name: Extract MariaDB service WSREP sync status
set_fact:
mariadb_sync_status: "{{ check_mariadb_sync_status.stdout.split('\t')[1] }}"
- name: Divide hosts by their MariaDB service WSREP sync status
group_by:
key: mariadb_sync_status_{{ mariadb_sync_status }}
- name: Fail when MariaDB service is not synced
fail:
msg: MariaDB service is not synced. Please wait for WSREP sync before proceeding.
when:
- groups.mariadb_sync_status_Synced is not defined or
inventory_hostname not in groups.mariadb_sync_status_Synced
when:
- groups.mariadb_port_alive_True is defined
- inventory_hostname in groups.mariadb_port_alive_True
when: not mariadb_recover | default(False)