Skip to content
Snippets Groups Projects
main.yml 2.65 KiB
Newer Older
---
- name: Starting first MariaDB container
  vars:
    service_name: "mariadb"
    service: "{{ mariadb_services[service_name] }}"
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    environment:
      KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
      BOOTSTRAP_ARGS: "--wsrep-new-cluster"
    image: "{{ service.image }}"
    labels:
      BOOTSTRAP:
    name: "{{ service.container_name }}"
    restart_policy: no
    volumes: "{{ service.volumes }}"
    dimensions: "{{ service.dimensions }}"
Mark Goddard's avatar
Mark Goddard committed
  listen: Bootstrap MariaDB cluster
# NOTE(yoctozepto): We have to loop this to avoid breaking on connection resets
- name: Wait for first MariaDB service port liveness
  wait_for:
    host: "{{ api_interface_address }}"
    port: "{{ mariadb_port }}"
    connect_timeout: 1
    timeout: 60
    search_regex: "MariaDB"
  register: check_mariadb_port
caoyuan's avatar
caoyuan committed
  until: check_mariadb_port is success
  retries: 10
  delay: 6
Mark Goddard's avatar
Mark Goddard committed
  listen: Bootstrap MariaDB cluster

- name: Wait for first MariaDB service to sync WSREP
  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: result
  until: result.stdout == "wsrep_local_state_comment\tSynced"
  retries: 10
  delay: 6
  no_log: true
  listen: Bootstrap MariaDB cluster

- name: Creating haproxy mysql user
  kolla_toolbox:
    module_name: mysql_user
    module_args:
      login_host: "{{ api_interface_address }}"
      login_port: "{{ mariadb_port }}"
      login_user: "{{ database_user }}"
      login_password: "{{ database_password }}"
      name: "haproxy"
      password: ""
      host: "%"
      priv: "*.*:USAGE"
  listen: Bootstrap MariaDB cluster
- name: Restart MariaDB on existing cluster members
  include_tasks: 'restart_services.yml'
    - groups.mariadb_port_alive_True is defined
    - inventory_hostname in groups.mariadb_port_alive_True
    - groups.mariadb_port_alive_True.index(inventory_hostname) % 4 == item
Jeffrey Zhang's avatar
Jeffrey Zhang committed
    - kolla_action != "config"
Mark Goddard's avatar
Mark Goddard committed
  listen: restart mariadb
- name: Start MariaDB on new nodes
  include_tasks: 'restart_services.yml'
    - bootstrap_host is not defined or bootstrap_host != inventory_hostname
    - groups.mariadb_port_alive_False is defined
    - inventory_hostname in groups.mariadb_port_alive_False
Jeffrey Zhang's avatar
Jeffrey Zhang committed
    - kolla_action != "config"
Mark Goddard's avatar
Mark Goddard committed
  listen: restart mariadb

- name: Ensure MariaDB is running normally on bootstrap host
  include_tasks: 'restart_services.yml'
  listen: Bootstrap MariaDB cluster