kolla-ansible/ansible/roles/mariadb/tasks/recover_cluster.yml
Benjamin Diaz 6f64549e1b Set bash as shell when executing mariadb recovery task
Added 'executable' argument to the shell action in the
'Comparing seqno value' task in the cluster recovery playbook.

Change-Id: I3e96a4a76b44ffb558b9a41cde16e66a8d0fab1a
Closes-Bug: #1729603
2017-11-27 15:07:38 -03:00

81 lines
2.6 KiB
YAML

---
- fail:
msg: "MariaDB cluster was not found. Is your inventory correct?"
when: not has_cluster | bool
- name: Checking if and mariadb containers are running
kolla_docker:
name: "mariadb"
action: "get_container_state"
register: container_state
- fail:
msg: "There are running MariaDB nodes, please stop them first."
when: container_state.Running | bool
any_errors_fatal: True
- name: Cleaning up temp file on mariadb hosts
file: path=/tmp/kolla_mariadb_grastate.dat state=absent
changed_when: false
check_mode: no
- name: Cleaning up temp file on localhost
local_action: file path=/tmp/kolla_mariadb_recover_inventory_name state=absent
changed_when: false
check_mode: no
run_once: true
- block:
- name: Copying grastate.dat file from mariadb container
command: docker cp mariadb:/var/lib/mysql/grastate.dat /tmp/kolla_mariadb_grastate.dat
changed_when: false
- name: Print the content of grastate.dat file
command: cat /tmp/kolla_mariadb_grastate.dat
register: cat_grastate
changed_when: false
- name: Registering mariadb seqno variable
set_fact:
seqno: "{{ (cat_grastate.stdout|from_yaml).seqno }}"
changed_when: false
- name: Comparing seqno value on all mariadb hosts
shell: "if [[ {{ hostvars[inventory_hostname]['seqno'] }} -lt {{ hostvars[item]['seqno'] }} ]]; then echo {{ hostvars[item]['seqno'] }}; fi"
args:
executable: /bin/bash
with_items: "{{ groups['mariadb'] }}"
changed_when: false
register: seqno_compare
- name: Writing hostname of host with the largest seqno to temp file
local_action: copy content={{ inventory_hostname }} dest=/tmp/kolla_mariadb_recover_inventory_name mode=0644
changed_when: false
when: seqno_compare.results | map(attribute='stdout') | join('') == ""
- name: Registering mariadb_recover_inventory_name from temp file
set_fact:
mariadb_recover_inventory_name: "{{ lookup('file', '/tmp/kolla_mariadb_recover_inventory_name') }}"
when:
- mariadb_recover_inventory_name is not defined
- set_fact:
bootstrap_host: "{{ mariadb_recover_inventory_name }}"
master_host: "{{ mariadb_recover_inventory_name }}"
changed_when: true
notify:
- Starting first MariaDB container
- restart slave mariadb
- restart master mariadb
- name: Cleaning up temp file on mariadb hosts
file: path=/tmp/kolla_mariadb_grastate.dat state=absent
changed_when: false
check_mode: no
- name: Cleaning up temp file on localhost
local_action: file path=/tmp/kolla_mariadb_recover_inventory_name state=absent
changed_when: false
check_mode: no
run_once: true