aboutsummaryrefslogtreecommitdiff
path: root/ansible/roles/mariadb/tasks/lookup_cluster.yml
blob: 48dd6e1ce8ac9d43f476acde7422d70fe70b7d8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
- name: Create MariaDB volume
  become: true
  kolla_container:
    action: "create_volume"
    common_options: "{{ docker_common_options }}"
    name: "mariadb"
  register: mariadb_volume
  when: migration_flag is not defined

- name: Divide hosts by their MariaDB volume availability
  group_by:
    key: "{{ mariadb_shard_group }}_had_volume_{{ mariadb_volume is not changed }}"
  changed_when: false

- name: Establish whether the cluster has already existed
  set_fact:
    mariadb_cluster_exists: "{{ groups[mariadb_shard_group + '_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_shard_group }}_port_alive_{{ check_mariadb_port_liveness is success }}"
      changed_when: false

    - name: Fail on existing but stopped cluster
      fail:
        msg: MariaDB cluster exists but is stopped. Please start it using kolla-ansible mariadb_recovery
      when:
        # NOTE(yoctozepto): we allow single-node cluster to start
        - groups[mariadb_shard_group] | length > 1
        - mariadb_cluster_exists
        - groups[mariadb_shard_group + '_port_alive_True'] is not defined

    - block:
        - name: Check MariaDB service WSREP sync status
          become: true
          kolla_toolbox:
            container_engine: "{{ kolla_container_engine }}"
            module_name: mysql_query
            module_args:
              login_db: "mysql"
              login_host: "{{ api_interface_address }}"
              login_port: "{{ mariadb_port }}"
              login_user: "{{ database_user }}"
              login_password: "{{ database_password }}"
              query: 'SHOW STATUS LIKE "wsrep_local_state_comment"'
          check_mode: false
          register: check_mariadb_sync_status

        - name: Extract MariaDB service WSREP sync status
          set_fact:
            mariadb_sync_status: "{{ check_mariadb_sync_status.query_result[0][0]['Value'] }}"
      when:
        - groups[mariadb_shard_group + '_port_alive_True'] is defined
        - inventory_hostname in groups[mariadb_shard_group + '_port_alive_True']

    - name: Divide hosts by their MariaDB service WSREP sync status
      group_by:
        key: "{{ mariadb_shard_group }}_sync_status_{{ mariadb_sync_status | default('NA') }}"
      changed_when: false

    - name: Fail when MariaDB services are not synced across the whole cluster
      fail:
        msg: MariaDB cluster is not synced. Please wait for WSREP sync before proceeding.
      when:
        - groups[mariadb_shard_group + '_port_alive_True'] is defined
        - groups[mariadb_shard_group + '_sync_status_Synced'] is not defined or
          groups[mariadb_shard_group + '_port_alive_True'] | sort != groups[mariadb_shard_group + '_sync_status_Synced'] | sort

  when: not mariadb_recover | default(False)